// tested by Hightail: https://github.com/dj3500/hightail #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define pb push_back #define INF 1001001001 #define FOR(i,n) for(int (i)=0;(i)<(n);++(i)) #define FORI(i,n) for(int (i)=1;(i)<=(n);++(i)) #define mp make_pair #define pii pair #define ll long long #define vi vector #define SZ(x) ((int)((x).size())) #define fi first #define se second #define wez(n) int (n); scanf("%d",&(n)); #define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m)); #define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k)); inline void pisz(int n) { printf("%d\n",n); } template ostream& operator<<(ostream &s,pair t) {return s<<"("< ostream& operator<<(ostream &s,vector t){FOR(i,SZ(t))s< tab[i+1]) cant[i] = 1; dp[0][n] = 1; REP(i,0,n-1) REP(a,1,n) if (dp[i][a] != 0) { dp[i][a] %= mod; for (int b = 1; i+b <= n && b <= a; ++b) { if (b >= 2 && tab[i+b-1] > tab[i+b]) break; ll th = dp[i][a] * fact[a] % mod * invfact[a-b] % mod; if (i == 0) th = dp[i][a];// * fact[b] % mod; dp[i+b][b] += th; } } ll res = 0; REP(a,1,n) res += dp[n][a] % mod; res = res % mod; if (res < 0) res += mod; cout << res; }