#include #include using namespace std; using namespace atcoder; typedef int64_t lint; #define rep(i, n) for(int i=0; i; using vvi = vector>; template inline void vin(vector& v) { rep(i, v.size()) cin >> v.at(i); } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template inline void drop(T x) { cout << x << endl; exit(0); } template void vout(vector v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; } constexpr lint LINF = LLONG_MAX/2; using mint = modint998244353; using vm = vector; int main() { lint N; cin >> N; vi v(N), w(N, LINF); vin(v); lint a=0, b=0, c=0, x, y, z; w[0] = v[0]; w[N-1] = v[N-1]; set s; s.insert(v[0]); s.insert(v[N-1]); repx(i, 1, (N+1)/2) { w[i] = w[i-1]; chmin(w[N-1-i], w[N-i]); if (chmin(w[i], v[i])) s.insert(v[i]); if (chmin(w[N-1-i], v[N-1-i])) s.insert(v[N-1-i]); } w.pb(LINF); reverse(all(w)); w.pb(LINF); reverse(all(w)); a = (N-1)/2+1; b = N/2+1; mint ans = 1; rep(i, N) { if (s.count(i)) continue; while(w[a] < i) a--; while(w[b] < i) b++; ans *= b-a-1-i; } std::cout << ans.val() << '\n'; }