from functools import cache from re import M import sys def printe(*args, end="\n", **kwargs): print(*args, end=end, file=sys.stderr, **kwargs) @cache def pow_mod(base: int, idx: int, mod: int) -> int: if idx == 0: return 1 % mod if idx == 1: return base % mod if idx % 2 == 0: idx //= 2 base **= 2 base %= mod return pow_mod(base, idx, mod) return base * pow_mod(base, idx - 1, mod) def main(): N = int(input()) A = list(map(int, input().split())) # 書き出してみると各ステップごとに到達するときの上り方のパターン数は、kステップについて考えると二項係数になっている # →ステップ数 ↓行動回数 # 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 # 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 # 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 0 # 0 0 0 1 3 6 10 15 21 28 36 45 55 66 78 91 0 # 0 0 0 0 1 4 10 20 35 56 84 120 165 220 286 364 0 # ... # kステップ目におけるi*A_kの和を求めるには、kC0+2*kC1+3*kC2+...+(k+1)kCk # がA_kの係数になるが、これは二項係数に関する和の公式から # https://a-iine.net/combination/ # (k+2)*2^(k-1)と整理できる MOD = 998244353 patterns = A[0] * pow_mod(2, N - 2, MOD) for idx, a_elm in enumerate(A[1:], 1): printe(patterns) if idx < N - 1: patterns += (idx + 2) * pow_mod(2, idx - 1, MOD) * \ a_elm * pow_mod(2, N - idx - 2, MOD) else: patterns += (idx + 2) * pow_mod(2, idx - 1, MOD) * \ a_elm patterns %= MOD print(patterns) if __name__ == "__main__": main()