#include using namespace std; constexpr int mod = 998244353; int main() { int N; cin >> N; vectorP(N),Q(N); for(int i = 0; i < N; i++) { cin >> P[i]; Q[P[i]] = i; } vectorfac(N); fac[0] = 1; for(int i = 1; i < N; i++) { fac[i] = fac[i-1]*i%mod; } long long ans = 1; int l = 0,r = 0,cnt = 0; for(int i = 0; i < N; i++) { if(i == 0) { cnt++; l = Q[i]; r = Q[i]; } else { if(l <= Q[i] && Q[i] <= r) { ans *= r-l-i+1; ans %= mod; continue; } if(Q[i] < l) { l = Q[i]; } else { r = Q[i]; } } } cout << ans << endl; }