#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; vector pre(N), aft(N); for (int i = 0; i < N; i ++) { pre[i] = F1.sum(0, iv[i]); F1.add(iv[i], 1); } for (int i = N - 1; i >= 0; i --) { aft[i] = F2.sum(iv[i], N); F2.add(iv[i], 1); } for (int i = 0; i < N; i ++) { int p = pre[i]; int a = aft[i]; int n = p + a, r = min(p, a); ans += kai[n] / fkai[r] / fkai[n - r]; } cout << ans.val() << endl; }