#include #define C 2222 using namespace std; int fact[C] , inverse_fact[C] , n , mod = 1e9 + 7 , f[C][C] , a[C]; int inverse(int x){ int ret = 1 , mul = x , k = mod - 2; while(k > 0){ if(k%2) ret = 1ll*ret*mul%mod; mul = 1ll*mul*mul%mod; k /= 2; } return ret; } void prepare(){ fact[0] = 1; for(int i = 1 ; i <= n ; i++) fact[i] = 1ll*fact[i - 1]*i%mod; for(int i = 0 ; i <= n ; i++) inverse_fact[i] = inverse(fact[i]); } int main(){ scanf("%d",&n); for(int i = 1 ; i <= n ; i++) scanf("%d",&a[i]); prepare(); for(int i = 1 ; i <= n ; i++){ if(a[i - 1] > a[i]) break; f[i][i] = 1; } for(int last = 1 ; last <= n ; last++) for(int size = 1 ; size <= n ; size++){ if(f[last][size] == 0) continue; for(int i = last + 1 ; i - last <= size ; i++){ if(i != last + 1 && a[i] < a[i - 1]) break; f[i][i - last] = (f[i][i - last] + 1ll*f[last][size]*fact[size]%mod*inverse_fact[size - (i - last)])%mod; } } int ans = 0; for(int i = 1 ; i <= n ; i++) ans = (ans + f[n][i])%mod; printf("%d",ans); return 0; }