/* i have a dream */ #include using namespace std; #define trace(x) {cerr << #x << "=" << x < ostream& operator<<(ostream& os, const set &p){os << "{ "; for (T x: p) os << x << " "; os << "}" << endl; return os;} template ostream& operator<<(ostream& os, const map &p){os << "{ "; for (pair x: p) os << x << " "; os << "}" << endl; return os;} template ostream& operator<<(ostream& os, const pair &p){os << "{" << p.first << ',' << p.second << "}";return os;} */ #define pi pair #define pipi pair > #define fi first #define se second const int MAX=2017; long long dp[MAX][MAX],n,a[MAX],f[MAX],I[MAX]; const long long mod=1e9+7; long long sum; bool sorted[MAX]; long long Exp(long long a,long long b) { if(b==0) return 1; if(b==1) return a; long long temp=a; long long val=Exp(a,b/2); val=(val*val)%mod; if(b%2==1) val=(val*a)%mod; return val; } void gen() { for(int i=1;i<=n;i++) { I[i]=Exp(f[i],mod-2); for(int j=1;ja[i-j+1]) break; } dp[i][i]=sorted[i]; } //for(int i=1;i<=n;i++) //cout<>n; f[0]=I[0]=1; sorted[0]=true; for(int i=1;i<=n;i++) { cin>>a[i]; f[i]=((long long)i*f[i-1])%mod; sorted[i]=sorted[i-1]&(a[i]>=a[i-1]); } gen(); for(int i=1;i<=n;i++) sum+=dp[n][i]; sum=sum%mod; cout<