#include #include using namespace std; using namespace atcoder; using ll=long long; using ld=long double; ld pie=3.141592653589793; ll inf=1444999994999999; ll mod=998244353; int main(){ ll n; cin >> n; vectorp(n); ll left=inf,right=0; vectormemo(n); for (ll i = 0; i < n; i++) { cin >> p[i]; memo[p[i]]=i; if (p[i]==0||p[i]==1) { left=min(left,i); right=max(right,i); } } ll ans=1; for (ll i = 2; i < n; i++) { if (left<=memo[i]&&memo[i]<=right) { ans*=(right-left-i+1); ans%=mod; } left=min(left,memo[i]); right=max(memo[i],right); } cout << ans << endl; }