#include using namespace std; template struct ModInt { int64_t x; ModInt() : x(0) {} ModInt(int64_t a) : x(a >= 0 ? a % mod : (a % mod + mod) % mod) {} inline unsigned getmod() const { return mod; } inline ModInt getprim() const { return ModInt(prim); } inline ModInt &operator+=(const ModInt &rhs) { x = x + rhs.x < mod ? x + rhs.x : x + rhs.x - mod; return *this; } inline ModInt &operator-=(const ModInt &rhs) { x = x - rhs.x < 0 ? mod + x - rhs.x : x - rhs.x; return *this; } inline ModInt &operator*=(const ModInt &rhs) { x = x * rhs.x % mod; return *this; } inline ModInt &operator/=(const ModInt &rhs) { return *this *= rhs.inv(); } inline ModInt modpow(uint64_t n) { if (x == 0) return x; ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } inline ModInt inv() const { return ModInt(x).modpow(mod - 2); } inline ModInt operator-() const { return ModInt(-x); } inline ModInt operator+(const ModInt &rhs) const { return ModInt(x) += rhs; } inline ModInt operator-(const ModInt &rhs) const { return ModInt(x) -= rhs; } inline ModInt operator*(const ModInt &rhs) const { return ModInt(x) *= rhs; } inline ModInt operator/(const ModInt &rhs) const { return ModInt(x) /= rhs; } inline bool operator==(const ModInt &rhs) const { return x == rhs.x; } inline bool operator!=(const ModInt &rhs) const { return x != rhs.x; } friend ostream &operator<<(ostream &os, const ModInt &rhs) { return os << rhs.x; } friend istream &operator>>(istream &is, ModInt &rhs) { int64_t i; is >> i; rhs = ModInt(i); return is; } }; // zero-based numbering template struct Fenwick { vector bit; int N; Fenwick(int n) : N(n) { bit.assign(n+1, 0); } // add w to a void add(int a, T w) { for (int x = ++a; x <= N; x += x & -x) bit[x] += w; } // sum [0, a) T sum(int a) { T ret = 0; for (int x = a; x > 0; x -= x & -x) ret += bit[x]; return ret; } // sum [a, b) T sum(int a, int b) { return sum(b) - sum(a); } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; cin >> N; using mod = ModInt<998244353>; Fenwick f(N), g(N); mod c = mod(2).modpow(N - 1); mod sum = 0; for (int i = 0; i < N; i++) { int p; cin >> p; p--; mod d = mod(2).modpow(i); f.add(p, 1); g.add(p, d); sum += c * (f.sum(p + 1, N) - g.sum(p + 1, N) / d); } cout << sum << '\n'; return 0; }