#include using namespace std; #define all(v) (v).begin(),(v).end() #define pb(x) push_back(x) #define sqr(x) ((x)*(x)) #define mp(x,y) make_pair((x),(y)) #define fast_io() ios_base::sync_with_stdio(0);cin.tie(0); #define fi first #define se second #define sz(v) ((int)v.size()) typedef pair pii; typedef vector vi; typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll MOD=(1e9 + 7); vector sub; ll memo[1500][1500]; ll n; ll fact[1500]; ll com[1500][1500]; ll pot(ll x,ll y){ if(y==0) return 1; if(y==1) return x; ll ans=1; if(y%2==1) ans=x; ll val=pot(x,y/2); val%=MOD; ans*=val; ans%=MOD; ans*=val; ans%=MOD; return ans; } ll inv(ll x){ x%=MOD; x+=MOD; x%=MOD; ll ans = pot(x,MOD-2); ans%=MOD; return ans; } ll C(ll x,ll y){ if(com[x][y]!=-1) return com[x][y]; ll ans=fact[x]; ans%=MOD; ans*=inv(fact[x-y]); ans%=MOD; com[x][y]=ans; return ans; } ll dp(int pos,int x){ int max=upper_bound(sub.begin(),sub.end(),pos)-sub.begin(); if(pos+x>sub[max]) return 0; if(pos+x==n) return 1; if(pos+x>n) return 0; if(memo[pos][x]!=-1) return memo[pos][x]; ll &ans=memo[pos][x]=0; for(int i=1;i<=x;i++){ ll valor=dp(pos+x,i); valor%=MOD; valor*=C(x,i); valor%=MOD; ans+=valor; ans%=MOD; } ans%=MOD; return ans; } int main(){ fast_io(); memset(memo,-1,sizeof(memo)); memset(com,-1,sizeof(com)); fact[0]=1; for(ll i=1;i<=1400;i++){ fact[i]=i*fact[i-1]; fact[i]%=MOD; } cin>>n; int val=0; vector v(n); for(int i=0;i>v[i]; if(v[i]