n = int(input()) a = list(map(int, input().split())) s = [0]*n for i in range(1,n): s[i] = s[i-1] + 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) # tot = sum(a) # mod = 998244353 # res = 0 # if n == 2: # res += (a[0]-a[-1]) # res %= mod # print(res) # exit(0) # cur = n # for aa in a: # cur -= 1 # res += (aa*cur)-(tot-aa) # tot -= aa # res %= mod # res += (a[0]-a[-1]) # res %= mod # print(res)