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