#include using namespace std; #include using namespace atcoder; using mint = modint998244353; int main () { int N; cin >> N; std::vector P(N), iv(N); for (int i = 0; i < N; i ++) { cin >> P[i]; iv[--P[i]] = i; } fenwick_tree F1(N), F2(N); vector kai(N + 1, mint(1)), fkai(N + 1, mint(1)); for (int i = 1; i <= N; i ++) { kai[i] = kai[i - 1] * i; } fkai[N] = fkai[N] / kai[N]; for (int i = N; i; i --) { fkai[i - 1] = fkai[i] * i; } mint ans = 0; for (int i = 0; i < N; i ++) { int p = F1.sum(0, i); int a = F2.sum(i + 1, N); int n = p + a, r = min(p, a); ans += kai[n] / fkai[r] / fkai[n - r]; } cout << ans.val() << endl; }