import sys input = lambda: sys.stdin.readline().rstrip() import math, random from bisect import bisect_right, bisect_left from itertools import product, permutations, combinations, combinations_with_replacement from collections import deque, defaultdict, Counter from heapq import heapify, heappush, heappop from functools import lru_cache, reduce inf = float('inf') def error(*args, sep=' ', end='\n'): print(*args, sep=sep, end=end, file=sys.stderr) def ltos(a, f=str, sep=' '): return sep.join(map(f, a)) # mod = 1000000007 mod = 998244353 # sys.setrecursionlimit(10**6) # ----------------------- # n = int(input()) A = list(map(int, input().split())) cnt = pow(2, n-1, mod)-1 ans = A[0] * cnt ans -= A[-1] * cnt print(ans % mod)