N = int(input()) a = list(map(int,input().split())) mod = 998244353 a2 = 1 for i in range(N-1): a2 = (a2*2)%mod a2 = (a2-1)%mod print((a2*(a[0]-a[-1]))%mod)