#include using namespace std; #define SPECIAL_NUM 1000000007 typedef long long ll; ll permutation(ll n,ll k) { ll num = 1; for (ll i=n; i>n-k; i--) { num*=i; num%=SPECIAL_NUM; } return num; } int tableNoPos[1200+1+1][1200+1+1];// positions of arrays not considered. only exactly of that size int main(){ int n; cin >> n; vector m(n); for(int m_i = 0; m_i < n; m_i++){ cin >> m[m_i]; } for (int i=0; i beenSortedFor(n); beenSortedFor[n-1]=1; for(int i=n-2; i>=0; i--) { if (m[i]>m[i+1]) { beenSortedFor[i]=1; } else { beenSortedFor[i]=beenSortedFor[i+1]+1; } } int minChunk = beenSortedFor[0]; int prev =1; for (int i=1; i minChunk) { beenSortedFor[i] = minChunk; } if (beenSortedFor[i]> minChunk) { beenSortedFor[i] = prev; } } for(int i=n-1; i>=0; i--) { int j; for(j=2; j<=beenSortedFor[i]; j++) { int subum = 0; ll ppperm = 1; for(int k=0; k<=j; k++) { //ll perm = permutation(j,k); subum += (ppperm * tableNoPos[i+j][k])%SPECIAL_NUM; subum %= SPECIAL_NUM; //cout << "P " << perm << " " << ppperm << '\n'; ppperm *= (j-k); ppperm %= SPECIAL_NUM; } tableNoPos[i][j] = subum; } } /* for(int i=1; i