// Problem: No.2250 Split Permutation // Contest: yukicoder // URL: https://yukicoder.me/problems/no/2250 // Memory Limit: 512 MB // Time Limit: 3000 ms #include #define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define dbg(x) cout << #x << " = " << (x) << "\n"; #define popcount(x) __builtin_popcountll((x)) #define all(v) (v).begin(), (v).end() #define pb emplace_back #define x first #define y second using namespace std; typedef long long ll; typedef pair pll; const int inf = 0x3f3f3f3f; const int mod = 998244353; int n; struct BIT { int sz; vector bit; BIT(int _n) { sz = _n; bit = vector(sz + 1, 0); } int lowbit(int x) { return x & -x; } void add(int x, ll v) { for (int i = x; i <= sz; i += lowbit(i)) { bit[i] += v; bit[i] %= mod; } } ll ask(int x) { ll ret = 0; for (int i = x; i >= 1; i -= lowbit(i)) { ret = ret + bit[i]; ret %= mod; } return ret; } }; ll ksm(ll x, ll n) { if (n < 0) n += mod - 1; ll res = 1; while (n) { if (n & 1) res = (res * x) % mod; x = x * x % mod; n >>= 1; } return res; } ll inv(ll x) { return ksm(x, mod - 2); } void solve() { cin >> n; BIT bit1(n), bit2(n); ll ans = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; ans = ans + ksm(2, n - 1) * (bit1.ask(n) - bit1.ask(x)) % mod; ans %= mod; ans = ans - (bit2.ask(n) - bit2.ask(x)) * ksm(2, n - 1) % mod * inv(ksm(2, i)) % mod; ans = (ans + mod) % mod; bit1.add(x, 1); bit2.add(x, ksm(2, i)); } cout << ans << "\n"; } int main() { fastio; int t = 1; // cin >> t; while (t--) { solve(); } return 0; }