#include #define MAXN 1220 #define BASE 1000000007 using namespace std; int N, M; int A[MAXN]; int StatesCount = 0; map >, int> States; long long Dp[2000000]; long long DpSearch(int Id, int CrPos, int AvPos) { if (Id == N) { return 1; } if (States.find(make_pair(Id, make_pair(CrPos, AvPos))) != States.end()) { return States.find(make_pair(Id, make_pair(CrPos, AvPos)))->second; } StatesCount++; States.insert(make_pair(make_pair(Id, make_pair(CrPos, AvPos)), StatesCount)); long long Res = 0; if ((A[Id] > A[Id - 1]) && (CrPos < AvPos)) { Res += DpSearch(Id + 1, CrPos + 1, AvPos) * (AvPos - CrPos); Res %= BASE; } Res += DpSearch(Id + 1, 1, CrPos); Res %= BASE; Dp[StatesCount] = Res; return Res; } int main() { cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } long long Res = 0; for (int i = 0; i < N; i++) { if ((i == 0) || (A[i] > A[i - 1])) { Res += DpSearch(i + 1, 1, i + 1); Res %= BASE; } else { break; } } cout << Res; return 0; }