#include #include #include #define llint long long #define mod 998244353 using namespace std; llint n; llint a[5005], b[5005]; int l[5005], r[5005]; llint dp[5005][5005]; int main(void) { cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; assert(n >= 1 && n <= 5000); for(int i = 1; i <= n; i++) b[i] = a[i]; sort(b+1, b+n+1); for(int i = 1; i <= n; i++) assert(b[i] == i); for(int i = 1; i <= n; i++){ for(int j = i; j >= 1; j--){ if(a[j] >= a[i]) l[i] = j; else break; } for(int j = i; j <= n; j++){ if(a[j] >= a[i]) r[i] = j; else break; } } dp[0][1] = 1; for(int i = 0; i <= n; i++){ for(int j = 1; j <= n; j++){ if(i+1 <= n && l[j] <= i+1 && i+1 <= r[j]) (dp[i+1][j] += dp[i][j]) %= mod; if(j+1 <= n) (dp[i][j+1] += dp[i][j]) %= mod; } } cout << dp[n][n] << endl; return 0; }