MOD = 998244353 half = pow(2, MOD - 2, MOD) def int2frac(n, m=None, N = 10000, D = 10000): """ Return (r, s) s.t. r = s * n (mod m) if such a pair exists. Otherwise, return (0, 0). Parameters ---------- n: an integer that will be represented as a fraction. m: A modulus used to represent n. N: An upperbound of r, which is the numerator of n. D: An upperbound of s, which is the denominator of n. """ def gcd(a, b): while b: a, b = b, a % b return a if m is None: m = MOD v = (m, 0) w = (n, 1) while w[0] > N: q = v[0] // w[0] v, w = w, (v[0] - q * w[0], v[1] - q * w[1]) if w[1] < 0: w = (-w[0], -w[1]) if w[1] <= D and gcd(w[0], w[1]) == 1: return w else: return (0, 0) def fwht(a) -> None: """ In-place Fast Walsh–Hadamard Transform of array a. Reference: https://en.wikipedia.org/wiki/Fast_Walsh%E2%80%93Hadamard_transform """ h = 1 while h < len(a): for i in range(0, len(a), h * 2): for j in range(i, i + h): x = a[j] y = a[j + h] a[j] = (x + y) % MOD a[j + h] = (x - y) % MOD h *= 2 def ifwht(a) -> None: """ In-place Inverse Fast Walsh–Hadamard Transform of array a. Reference: https://en.wikipedia.org/wiki/Fast_Walsh%E2%80%93Hadamard_transform """ h = 1 while h < len(a): for i in range(0, len(a), h * 2): for j in range(i, i + h): x = a[j] y = a[j + h] a[j] = (x + y) * half % MOD a[j + h] = (x - y) * half % MOD h *= 2 N = int(input()) As = list(map(int, input().split())) # assert 1 <= N <= 2 * 10 ** 3 # assert all(0 <= A <= 10 ** 5 for A in As) # assert N + 1 == len(As) # assert As[0] sumAs = sum(As) invsumAs = pow(sum(As), MOD - 2, MOD) for i in range(N + 1): As[i] *= invsumAs As[i] %= MOD # print([int2frac(A) for A in As]) z = 1 << N.bit_length() e0 = [0] * z e0[0] = 1 fwht(e0) As_fwht = As + [0] * (z - N - 1) fwht(As_fwht) fwhts = [] for i, A in enumerate(As): t = [0] * z t[i] = A fwht(t) fwhts.append(t) q = [pow(1 - As_fwht[k] + fwhts[0][k], MOD - 2, MOD) * As[0] % MOD * e0[k] % MOD for k in range(z)] ifwht(q) psum = [0] * z for x in range(1, N + 1): p = [pow(1 - As_fwht[k] + fwhts[x][k] + fwhts[0][k], MOD - 2, MOD) * As[x] % MOD * e0[k] % MOD for k in range(z)] ifwht(p) for i, e in enumerate(p): psum[i] += e psum[i] %= MOD answer = q[0] for xor in range(z): answer += psum[xor] * q[xor] % MOD answer %= MOD print((1 - answer) % MOD)