#include #define mp make_pair #define pb push_back #define fi first #define se second #define MOD 1000000007LL using namespace std; typedef long long ll; typedef pair ii; typedef vector vi; ll memo[1201][1201]; ll chose[1201][1201]; ll fact[1201]; vi v; int pd(int curn, int lastsz) { if(curn == v.size()) { return 1; } else if(memo[curn][lastsz] != -1){ return memo[curn][lastsz]; } else { ll ans = pd(curn+1, 1) * lastsz; ans %= MOD; for(int i = 1; i < lastsz; i++) { if(v[curn + i] > v[curn + i - 1]) { ll cur = pd(curn + i + 1, i + 1); cur *= chose[lastsz][i+1]; cur %= MOD; cur *= fact[i+1]; cur %= MOD; ans += cur; ans %= MOD; } else { break; } } return memo[curn][lastsz] = ans; } } int main() { ios_base::sync_with_stdio(0); for(int i = 0; i <= 1200; i++) { chose[i][0] = 1; chose[i][i] = 1; } for(int i = 2; i <= 1200; i++) { for(int j = 1; j < i; j++) { chose[i][j] = (chose[i-1][j] + chose[i-1][j-1])%MOD; } } fact[0] = 1; for(int i = 1; i <= 1200; i++) { fact[i] = fact[i-1]*i; fact[i] %= MOD; } int n; cin >> n; for(int i = 0; i < n; i++) { int a; cin >> a; v.pb(a); } memset(memo, -1, sizeof memo); ll ans = pd(1, 1); for(int i = 1; i < n; i++) { if(v[i] > v[i-1]) { ans += pd(i+1, i+1); ans %= MOD; } else { break; } } cout << ans << endl; return 0; }