#include #include #include #include #include using namespace std; using namespace __gnu_pbds; template > using nset = tree; using ll = long long; using mint = atcoder::modint998244353; const int mod = 998244353; class FPC{ private: int size; vector ff, fi; public: FPC(int _n = 0) : size(_n), ff(_n + 1), fi(_n + 1){ ff[0] = fi[0] = 1; for(int i = 1;i < size;i++){ ff[i] = ff[i - 1] * i; fi[i] = ff[i].inv(); } } mint fact(int n) const{ assert(0 <= n && n <= size); return ff[n]; } mint faci(int n) const{ assert(0 <= n && n <= size); return fi[n]; } mint parm(int n, int r) const{ assert(0 <= n && n <= size); assert(0 <= r && r <= size); return ff[n] * fi[r]; } mint comb(int n, int r) const{ assert(0 <= n && n <= size); assert(0 <= r && r <= size); assert(n >= r); return ff[n] * fi[r] * fi[n - r]; } }; int N; int P[303030]; pair ff[303030], bb[303030]; int main(void){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; for(int i = 0;i < N;i++){ cin >> P[i]; P[i]--; } FPC fpc(N); atcoder::fenwick_tree fbt(N), bbt(N); for(int i = 0;i < N;i++){ int s = fbt.sum(0, P[i]); // s d ff[i] = {s, i - s}; bb[i] = {P[i] - s, N - 1 - i - (P[i] - s)}; fbt.add(P[i], 1); } mint ans = 0; for(int i = 0;i < N;i++){ ans += fpc.comb(ff[i].first + bb[i].second, ff[i].first) * fpc.comb(ff[i].second + bb[i].first, bb[i].first); } cout << ans.val() << endl; return 0; }