#include using namespace std; const int MAX = 1000000007; long long factorial(int a){ long long total=1; for(int i=2; i < a; i++){ total*=i; total %= MAX; } return total; } long long poss(long long arr[], int length, int prevLength){ if(length == 0 || prevLength == 1){ return 1; } int sortedLength=1; for(int i = 0; i < min(length - 1, prevLength - 1); i++){ if(arr[i+1] >= arr[i]){ sortedLength++; }else{ break; } } long long total=0; for(int i=1; i <= sortedLength; i++){ total+=factorial(i)*poss(arr+i, length - i, i); total%=MAX; } return total%=MAX; } int main() { int N; cin>>N; long long arr[N]; for(int i = 0; i < N; i++){ cin>>arr[i]; } cout<