#include #include #include #include #include using namespace std; int fact(int n) { int total = 1; for (int i = n; i >= 1; i--) { total = (total * i) % 1000000007; } return total; } bool isSorted(int v[], int low, int max) { for (int i = low; i < max-1; i++) { if (v[i] > v[i+1]) return false; } return true; } long test(int v[], int size, int max) { if (size == 0) return 1; if (size == 1) return max; int total; for (int i = 1; i <= max; i++) { if (isSorted(v, 0, i)) { int res = test(v+i, size-i, i) % 1000000007; if (res != 0) total += (fact(i) * res) % 1000000007; } } return total; } long test1(int v[], int size, int max) { if (size == 0) return 1; if (size == 1) return max; int total = 0; for (int i = 1; i <= max; i++) { if (isSorted(v, 0, i)) { total += test(v+i, size-i, i) % 1000000007; } } return total; } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n; cin >> n; int v[1200]; int a; for (int i = 0; i < n; i++) { cin >> a; v[i] = a; } cout << test1(v, n, n) << endl; return 0; }