N=int(input()) A=list(map(int, input().split())) mod=998244353 B=A.copy() def mergecount(A): cnt = 0 n = len(A) if n>1: A1 = A[:n>>1] A2 = A[n>>1:] cnt += mergecount(A1) cnt += mergecount(A2) i1=0 i2=0 for i in range(n): if i2 == len(A2): A[i] = A1[i1] i1 += 1 elif i1 == len(A1): A[i] = A2[i2] i2 += 1 elif A1[i1] <= A2[i2]: A[i] = A1[i1] i1 += 1 else: A[i] = A2[i2] i2 += 1 cnt += n//2 - i1 return cnt al=mergecount(B)*(pow(2,N-1,mod)) al%=mod class Bit: def __init__(self, size): self.data = [0] * (size + 1) self.size = size #i: index(0-index)までの和 def sum(self, i): i+=2 s = 0 while i > 0: s += self.data[i] i -= i & -i return s def add(self, i, x): i += 2 while i <= self.size: self.data[i] += x i += i & -i C=[1] for i in range(N): c=C[-1]*2 c%=mod C.append(c) bit=Bit(N+10) ans=0 for i in range(N): a=A[i] d=bit.sum(N+1)-bit.sum(a) d%=mod ans=ans*2+d ans%=mod bit.add(a,C[i]) #C=[] #for j in range(N): # C.append(bit.sum(j+1)-bit.sum(j)) #print(C) print((al-ans)%mod)