Problem:
Score : 1600 points

Problem Statement

Snuke found a random number generator.
It generates an integer between 0 and 2^N-1 (inclusive).
An integer sequence A_0, A_1, \cdots, A_{2^N-1} represents the probability that each of these integers is generated. The integer i (0 \leq i \leq 2^N-1) is generated with probability A_i / S, where S = \sum_{i=0}^{2^N-1} A_i. The process of generating an integer is done independently each time the generator is executed.

Snuke has an integer X, which is now 0.
He can perform the following operation any number of times:

Generate an integer v with the generator and replace X with X \oplus v, where \oplus denotes the bitwise XOR.

For each integer i (0 \leq i \leq 2^N-1), find the expected number of operations until X becomes i, and print it modulo 998244353.
More formally, represent the expected number of operations as an irreducible fraction P/Q. Then, there exists a unique integer R such that R \times Q \equiv P \mod 998244353,\ 0 \leq R < 998244353, so print this R.

We can prove that, for every i, the expected number of operations until X becomes i is a finite rational number, and its integer representation modulo 998244353 can be defined.

Constraints

1 \leq N \leq 18

1 \leq A_i \leq 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_0 A_1 \cdots A_{2^N-1}

Output

Print 2^N lines.
The (i+1)-th line (0 \leq i \leq 2^N-1) should contain the expected number of operations until X becomes i, modulo 998244353.

Sample Input 1

2
1 1 1 1

Sample Output 1

0
4
4
4

X=0 after zero operations, so the expected number of operations until X becomes 0 is 0.

Also, from any state, the value of X after one operation is 0, 1, 2 or 3 with equal probability.
Thus, the expected numbers of operations until X becomes 1, 2 and 3 are all 4.

Sample Input 2

2
1 2 1 2

Sample Output 2

0
499122180
4
499122180

The expected numbers of operations until X becomes 0, 1, 2 and 3 are 0, 7/2, 4 and 7/2, respectively.

Sample Input 3

4
337 780 799 10 796 875 331 223 941 67 148 483 390 565 116 355

Sample Output 3

0
468683018
635850749
96019779
657074071
24757563
745107950
665159588
551278361
143136064
557841197
185790407
988018173
247117461
129098626
789682908

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>

using namespace std;

const int max_n = (1 << 18) + 5, mod = 998244353;

int mul(int x, int y) {
    return (1LL * x * y) % mod;
}

int power(int a, int b) {
    if (b == 0) {
        return 1 % mod;
    }
    if (b % 2 == 0) {
        return power(mul(a, a), b / 2);
    }
    return mul(a, power(a, b - 1));
}

int inv(int x) {
    return power(x, mod - 2);
}

int n, sum, a[max_n], b[max_n], ans[max_n];

void product(int *a, int *b, int *c) {
    for (int i = 0; i < (1 << n); ++i) {
        for (int j = 0; j < (1 << n); ++j) {
            c[i ^ j] += mul(a[i], b[j]);
            c[i ^ j] %= mod;
        }
    }
}

int inv2 = inv(2);

template<bool inverse>
void convolve(int n, int *a) {
    if (n == 1) {
        return;
    }
    for (int i = 0; i < n / 2; ++i) {
        int a0 = a[i], a1 = a[i + n / 2];
        a[i] = (a0 + a1) % mod;
        a[i + n / 2] = (a0 + mod - a1) % mod;
        if (inverse) {
            a[i] = mul(a[i], inv2);
            a[i + n / 2] = mul(a[i + n / 2], inv2);
        }
    }
    convolve<inverse>(n / 2, a);
    convolve<inverse>(n / 2, a + n / 2);
}

void fast_product(int n, int *a, int *b, int *c) {
    if (n == 1) {
        c[0] = mul(a[0], b[0]);
        return;
    }
    for (int i = 0; i < n / 2; ++i) {
        int a0 = a[i], a1 = a[i + n / 2];
        a[i] = (a0 + a1) % mod;
        a[i + n / 2] = (a0 + mod - a1) % mod;

        int b0 = b[i], b1 = b[i + n / 2];
        b[i] = (b0 + b1) % mod;
        b[i + n / 2] = (b0 + mod - b1) % mod;
    }
    fast_product(n / 2, a, b, c);
    fast_product(n / 2, a + n / 2, b + n / 2, c + n / 2);
    for (int i = 0; i < n / 2; ++i) {
        int c0 = c[i], c1 = c[i + n / 2];
        c[i] = mul(c0 + c1, inv2);
        c[i + n / 2] = mul(c0 + mod - c1, inv2);
    }
}

void write(int *a) {
    for (int i = 0; i < (1 << n); ++i) {
        printf("%d ", a[i]);
    }
    puts("");
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 0; i < (1 << n); ++i) {
        scanf("%d", &a[i]);
        sum += a[i];
    }
    sum = inv(sum);
    for (int i = 0; i < (1 << n); ++i) {
        a[i] = mul(a[i], sum);
    }
    a[0] = (a[0] + mod - 1) % mod;
    b[0] = (1 << n) - 1;
    for (int i = 1; i < (1 << n); ++i) {
        b[i] = mod - 1;
    }
    convolve<false>(1 << n, b);
    convolve<false>(1 << n, a);
    for (int i = 0; i < (1 << n); ++i) {
        ans[i] = mul(inv(a[i]), b[i]);
        ans[0] += mod - ans[i];
        ans[0] %= mod;
    }
    convolve<true>(1 << n, ans);
    for (int i = 0; i < (1 << n); ++i) {
        printf("%d\n", ans[i]);
    }
    return 0;
}