#include #include using namespace std; typedef long long LL; const LL MOD = 1000 * 1000 * 1000 + 7; int N; int M[1200]; LL ways[1201][1201]; int main(){ scanf("%d ", &N); for (int i = 0; i < N; i++) scanf("%d ", &M[i]); // Dynamic programming from the back ways[N][0] = 1; for (int i = N-1; i >= 0; i--){ ways[i][1] = 1; for (int j = i+1; j < N; j++){ if (M[j-1] > M[j]) break; int cl = j - i + 1; LL prod = 1; for (int k = 0; k < cl+1; k++){ if (k > 0 && ways[j + 1][k] == 0) break; ways[i][cl] = (ways[i][cl] + prod * ways[j + 1][k]) % MOD; prod = (prod * (cl - k)) % MOD; } } } LL total = 0; for (int i = 1; i <= N; i++) total = (total + ways[0][i]) % MOD; printf("%lld\n", total); }