import sys input = sys.stdin.readline class FenwickTree: def __init__(self, size): self.data = [0] * (size + 1) self.size = size # i is exclusive def prefix_sum(self, i): s = 0 while i > 0: s = (s + self.data[i]) % mod i -= i & -i return s def add(self, i, x): i += 1 while i <= self.size: self.data[i] = (self.data[i] + x) % mod i += i & -i mod = 998244353 N = int(input()) P = list(map(lambda x: int(x)-1, input().split())) pow2 = [1] * (N+1) for i in range(1, N+1): pow2[i] = pow2[i-1] * 2 % mod ft_cnt = FenwickTree(N) ft_val = FenwickTree(N) ans = 0 for i, x in enumerate(P): cnt = ft_cnt.prefix_sum(N) - ft_cnt.prefix_sum(x) val = ft_val.prefix_sum(N) - ft_val.prefix_sum(x) ans = (ans + pow2[N-1] * (cnt - val * pow(pow2[i], mod-2, mod))) % mod ft_cnt.add(x, 1) ft_val.add(x, pow2[i]) print(ans)