#include #include #include #include #include #include #include #include #include #include #define MAXN 102000 #define pb push_back #define mod 1000000007 using namespace std; typedef long long lint; int N; int n; int ar[MAXN]; int dp[1210][1210]; int us[1210][1210]; int perm[1210][1210]; int f(int n,int k){ if(n == N + 1) return 1; int &ret = dp[n][k]; if(us[n][k]) return ret; us[n][k] = 1; ret = 0; for(int i = n ; i <= N && (i < n+k || k == 0) ; i++){ if(i > n && ar[i] < ar[i-1]) return ret; if(k == 0) perm[k][i-n+1] = 1; //printf("%d %d\n",i+1,i-n+1); ret += ((long long)f(i+1,i-n+1) * perm[k][i-n+1])%mod; ret %= mod; } return ret; } int main(){ scanf(" %d",&n); N = n; for(int i = 1 ; i <= n ; i++){ scanf(" %d",&ar[i]); } for(int i = 0 ; i < 1210 ; i++) for(int j = 0 ; j <= i ; j ++){ if(j == 0) perm[i][j] = 1; else perm[i][j] = ((long long)perm[i][j-1] * (i-j+1))%mod; } printf("%d\n", f(1,0)); return 0; }