import sys import math #from collections import deque, defaultdict, Counter #import heapq #import bisect #import itertools #import functools # 外部ライブラリ(AtCoder環境で利用可能) #from sortedcontainers import SortedList, SortedSet, SortedDict #from atcoder.dsu import DSU #from atcoder.segtree import SegTree #from atcoder.lazysegtree import LazySegTree #from atcoder.fenwicktree import FenwickTree # 入力高速化 #input = sys.stdin.readline # 再帰回数上限 # よくあるmod #MOD = 1000000007 MOD = 998244353 def solve(): # 解答ここから N = int(input()) bit_cnt = [0] * 20 powers = [(2**i) % MOD for i in range(20)] for n in range(N): x = n i = 0 while x > 0: bit_cnt[i] += x % 2 x //= 2 i += 1 ans = 0 A = list(map(int, input().split(' '))) for i in range(N): x = N y = i j = 0 cur = 0 while x > 0: if y % 2 == 0: cur = (cur + powers[j] * bit_cnt[j]) % MOD else: cur = (cur + powers[j] * (N - bit_cnt[j])) % MOD x //= 2 y //= 2 j += 1 ans = (ans + A[i] * cur) % MOD print(ans) if __name__ == '__main__': T = 1 for _ in range(T): solve()