#ごめんなさいpypy遅くないです import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import gcd,log input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) class BIT(): def __init__(self,n,mod=0): self.BIT = [0]*(n+1) self.num = n self.mod = mod """ return A[1] + A[2] + ... A[idx] in O(log n) """ def query(self,idx): res_sum = 0 mod = self.mod while idx > 0: res_sum += self.BIT[idx] if mod: res_sum %= mod idx -= idx&(-idx) return res_sum """ A[idx] += in O(log n) """ def update(self,idx,x): mod = self.mod while idx <= self.num: self.BIT[idx] += x if mod: self.BIT[idx] %= mod idx += idx&(-idx) return mod = 998244353 N = int(input()) P = li() fw = BIT(N,mod=998244353) fw2 = BIT(N) res = 0 S = 0 i2 = pow(2,mod-2,mod) inv = 0 for i in range(N): tmp = S - fw.query(P[i]) res += tmp * pow(i2,i,mod) % mod res %= mod inv += i - fw2.query(P[i]) fw.update(P[i],pow(2,i,mod)) S += pow(2,i,mod) fw2.update(P[i],1) minus = res * pow(2,N-1,mod) % mod ans = inv * pow(2,N-1,mod) % mod print((ans-minus) % mod)