#include #define M 1000000007ll #define ll long long #define MIN(x, y) ((x) < (y) ? (x) : (y)) #define MAX(x, y) ((x) < (y) ? (y) : (x)) using namespace std; const int N = 200020; ll C[2020][2020], S[2020][2020]; int n; int a[2020]; ll answer; int main() { scanf("%d", &n); for(int i = 1; i <= n; ++ i) scanf("%d", &a[i]); C[0][0] = 1; for(int i = 0; i <= n; ++ i) { ll now = 1; C[i][0] = 1; for(int j = i + 1; j <= n; ++ j) { now = (now * j) % M; C[j][j - i] = now; } } S[n + 1][0] = 1; for(int i = n + 1; i > 0; -- i) { for(int j = i - 1; j > 0; -- j) { if((i - 1 - j) && a[j] > a[j + 1]) break; for(int p = 0; p <= i - j; ++ p) { ll x = (S[i][p] * C[i - j][p]) % M; S[j][i - j] = (S[j][i - j] + x) % M; } } } for(int p = 0; p <= n; ++ p) answer = (answer + S[1][p]) % M; printf("%lld", answer); }