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