#include using namespace std; const int N = 1205 , mod = 1e9 + 7; inline int add(int a , int b){ int res = a + b; if(res >= mod) res -= mod; return res; } inline int mult(int a , int b){ long long res = (long long) a * 1LL * b; return res % mod; } int power(int a , int b){ int res = 1; while(b){ if(b & 1){ res = mult(res , a); } a = mult(a , a); b >>= 1; } return res; } int arr[N]; int fact[N]; int inv[N]; int dp[N][N]; int n; int ans; int ncr(int a , int b){ int res = fact[a]; res = mult(res , mult(inv[b] , inv[a-b])); return res; } int solve(int idx , int lim){ if(idx == n + 1) return 1; if(dp[idx][lim] != -1) return dp[idx][lim]; int res = 0; for(int i = idx ; i <= n and i < idx + lim ; i++){ if(arr[i] < arr[i-1] and i != idx) break; res = add(res , mult(solve(i + 1 , i - idx + 1) , mult(fact[lim] , inv[lim - i + idx - 1]))); } return dp[idx][lim] = res; } int main(){ scanf("%d" , &n); memset(dp , -1 , sizeof(dp)); fact[0] = 1 , inv[0] = 1; for(int i = 1 ; i < N ; i++){ fact[i] = mult(fact[i-1] , i); inv[i] = power(fact[i] , mod - 2); } for(int i = 1 ; i <= n ; i++){ scanf("%d" , &arr[i]); } for(int i = 1 ; i <= n ; i++){ if(arr[i] >= arr[i-1]){ ans = add(ans , solve(i + 1 , i)); } else break; } printf("%d\n", ans); }