#include #include #include #define ALL(V) std::begin(V), std::end(V) using ll = long long; using modint = atcoder::modint998244353; int main() { int N; std::cin >> N; std::vector P(N), rP(N); for (int i = 0; i < N; i++) { std::cin >> P[i]; P[i]--; rP[P[i]] = i; } std::vector pow2(N + 10); pow2[0] = 1; for (int i = 0; i < N + 9; i++) pow2[i + 1] = pow2[i] * 2; modint ans = 0; { atcoder::fenwick_tree cnt(N); for (int i = 0; i < N; i++) { int idx = rP[i]; auto sum = cnt.sum(idx, N); ans += sum; cnt.add(idx, 1); } ans *= pow2[N - 1]; } atcoder::fenwick_tree ft(N); for (int i = 0; i < N; i++) { int idx = rP[i]; auto sum = ft.sum(idx, N); int p = N - 1 + idx; ans -= sum * pow2[p]; ft.add(idx, pow2[idx].inv()); } std::cout << ans.val() << std::endl; return 0; }