n = int(input()) a = list(map(int, input().split())) mod = 998244353 res = 0 for i in range(n): res += a[i]*(pow(2, n-1-i, mod)-1) res -= a[i]*(pow(2, i, mod)-1) print(res)