#include #include #include using namespace std; typedef long long ll; const int MOD = 1e9+7; int n; int A[1501]; int DP[1501][1501]; int fac[1501], rev[1501], rfac[1501]; void set() { fac[0] = 1; for (int i = 1; i < 1501; i++) fac[i] = (ll)i*fac[i-1]%MOD; rev[1] = 1; for (int i = 2; i < 1501; i++) rev[i] = (ll)rev[MOD%i]*(MOD-MOD/i)%MOD; rfac[0] = 1; for (int i = 1; i < 1501; i++) rfac[i] = (ll)rfac[i-1]*rev[i]%MOD; } int ask(int O, int P) { if ( DP[O][P] == -1 ) { DP[O][P] = 0; if ( O+P > n+1 ) return DP[O][P]; int p = 0; for (int i = O; i < O+P; i++) { if ( A[i] < p ) return DP[O][P]; p = A[i]; } if ( O+P == n+1 ) return DP[O][P] = 1; for (int Pi = 1; Pi <= P; Pi++) DP[O][P] += (ll)ask(O+P, Pi)*fac[P]%MOD*rfac[P-Pi]%MOD, DP[O][P] %= MOD; } return DP[O][P]; } int main() { set(); memset(DP, -1, sizeof(DP)); scanf("%d", &n); for (int ni = 1; ni <= n; ni++) scanf("%d", &A[ni]); int ans = 0; for (int ni = 1; ni <= n; ni++) ans += ask(1, ni), ans %= MOD; printf("%d\n", ans); }