#include using namespace std; #include #include using namespace __gnu_pbds; #define ordered_set tree, rb_tree_tag, tree_order_statistics_node_update> #define ff first #define ss second #define pb push_back #define mp make_pair #define all(x) x.begin(),x.end() #define sz(x) ((int)x.size()) #define eps 1e-9 #define fast_cin ios_base::sync_with_stdio(false) const int MOD = 1e9+7; typedef long long ll; typedef pair pii; const int MAXN = 1203; int dp[MAXN]; int C[MAXN][MAXN]; int ar[MAXN]; ll DP[MAXN][MAXN]; ll f[MAXN]; int n; ll go(int idx, int can) { if(idx==n+1) return 1; if(DP[idx][can]!=-1) return DP[idx][can]; ll ret=0; int mini=min(dp[idx],can); for(int i=1;i<=mini and idx+i<=n+1;i++) { ll val = go(idx+i,i); if(idx!=1) val*=1LL*C[can][i]; if(val>=MOD) val%=MOD; if(idx!=1) val*=f[i]; if(val>=MOD) val%=MOD; ret+=val; if(ret>=MOD) ret-=MOD; } return DP[idx][can]=ret; } int main() { // freopen("TASK.in","r",stdin);freopen("TASK.out","w",stdout); cin>>n; for(int i=1;i<=n;i++) scanf("%d",&ar[i]); dp[n]=1; C[0][0]=1; f[0]=1; for(int i=1;i=MOD) C[i][j]-=MOD; } for(int i=n-1;i>=1;i--) { if(ar[i]