// Made By Haireden Aibyn #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define fname "" #define INF 2147483647 #define MOD 1000000007 #define mp make_pair #define F first #define S second #define sc scanf #define all(x) x.begin(), x.end() #define size(x) int(x.size()) #define pr printf #define deb(x) cerr << " | " << #x << " = " << x #define pb push_back #define ex exit(0) #define y1 y4 typedef long long ll; typedef unsigned long long ull; const int N = 1222; ll inv[N], f[N], d[N][N]; int a[N]; ll binpow(ll x, ll p) { ll res = 1LL; while (p) { if (p & 1) res *= x, res %= MOD; x *= x; x %= MOD; p >>= 1; } return res; } ll cnk(int n, int k) { return (f[n] * inv[n - k]) % MOD; } int main() { int n; sc("%d", &n); for (int i = 1; i <= n; i++) { sc("%d", &a[i]); } f[0] = 1LL; inv[0] = 1LL; for (int i = 1; i <= n; i++) { f[i] = (f[i - 1] * 1LL * i) % MOD; inv[i] = binpow(f[i], MOD - 2); } reverse(a + 1, a + 1 + n); d[0][0] = 1LL; for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { if (i != j && a[j - 1] < a[j]) { break; } for (int take = 0; take <= (j - i + 1); take++) { d[j][(j - i + 1)] += (d[i - 1][take] * cnk((j - i + 1), take)) % MOD; if (d[j][j - i + 1] >= MOD) d[j][(j - i + 1)] -= MOD; } } } ll ans = 0; for (int i = 1; i <= n; i++) { ans += d[n][i]; if (ans >= MOD) ans -= MOD; } cout << ans; return 0; }