import sys input = sys.stdin.readline from collections import * class BIT: def __init__(self, n): self.n = n self.bit = [0]*(n+1) def add(self, i, x): i += 1 while i<=self.n: self.bit[i] += x i += i&(-i) def acc(self, i): s = 0 while i>0: s += self.bit[i] i -= i&(-i) return s N = int(input()) P = list(map(int, input().split())) P = list(map(lambda x: x-1, P)) MOD = 998244353 bit = BIT(N) inv = 0 for i in range(N): inv += i-bit.acc(P[i]) bit.add(P[i], 1) ans = inv*pow(2, N-1, MOD)%MOD bit = BIT(N) for i in range(N): ans -= pow(2, N-1-i, MOD)*(bit.acc(N)-bit.acc(P[i]))%MOD ans %= MOD bit.add(P[i], pow(2, i, MOD)) print(ans)