N = int(input()) A = list(map(int, input().split())) mod = 998244353 print((pow(2,N-1,mod)-1)*(A[0]-A[-1])%mod)