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 Haskell (GHC 7.10.3) (judge verdict: Time Limit Exceeded)

-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
import Data.Char (isSpace)
import Data.Bits (xor)
import Control.Monad (forM_,when)
import Control.Monad.ST
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.Vector.Generic as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.ByteString.Char8 as BS
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray
import System.Environment (getArgs)
import Debug.Trace
---
import Data.Coerce
import qualified Data.Vector.Generic
import qualified Data.Vector.Generic.Mutable
import qualified Data.Array.Base
import qualified Unsafe.Coerce

type NN = N
type Mat = UArray (Int,Int) NN
type Vec = U.Vector NN
{-
type NN = Rational
type Mat = Array (Int,Int) Rational
type Vec = V.Vector NN
-}

main = do
  n :: Int <- readLn -- 1 <= n <= 18
  as <- U.unfoldrN (2^n) (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let s = U.sum as :: Int
      !as' = G.map fromIntegral (V.convert as) :: Vec
      !s' = recip (fromIntegral s) :: NN
      coeffMat :: Mat
      coeffMat = array ((1,1),(2^n-1,2^n)) $
        [ ((i,j),v)
        | i <- [1..2^n-1]
        , j <- [1..2^n-1]
        , let v | i == j = 1 - (as' G.! 0) * s'
                | otherwise = - (as' G.! (i `xor` j)) * s'
        ]
        ++ [((i,2^n),1) | i <- [1..2^n-1]]
      coeffMatV :: V.Vector Vec
      coeffMatV = V.generate (2^n-1) $ \i ->
        G.generate (2^n) $ \j ->
        if j == 2^n-1
        then 1
        else if i == j
             then 1 - (as' G.! 0) * s'
             else - (as' G.! ((i+1) `xor` (j+1))) * s'
  let result = solve coeffMat
  let resultV = solveV coeffMatV
  print 0
  args <- getArgs
  case args of
    "array":_ -> do
      forM_ [1..2^n-1] $ \j -> do
        print $ result!(j,2^n) / result!(j,j)
    _ -> do -- print resultV
            V.imapM_ (\j row -> print $ row G.! (2^n-1) / row G.! j) resultV

-- 行基本変形を行う
solve :: (Eq k, Fractional k, IArray arr k) => arr (Int,Int) k -> arr (Int,Int) k
solve m | i0 == j0 = loop i0 m
        | otherwise = error "not supported"
  where
    b@((i0,j0),(iN,_)) = bounds m
    loop !i !m
      | i > iN = m
      | otherwise = case [(k,w) | k <- [i..iN], let w = m!(k,i), w /= 0] of
          (!k,!w):_ -> let !r = recip w -- r == recip (m!(k,i))
                       in loop (i+1) $ array b
                          [ ((i'',j),v)
                          | (i',j) <- indices m
                          , let !v | i' == k = m!(i',j)
                                   | otherwise = m!(i',j) - m!(k,j)*m!(i',i)*r
                                !i''  | i' == k = i
                                      | i' == i = k
                                      | otherwise = i'
                          ]
          [] -> error "singular matrix"

solveV :: forall vector k. (Eq k, Fractional k, G.Vector vector k, Show k, Show (vector k)) => V.Vector (vector k) -> V.Vector (vector k)
solveV m = runST $ do
  m' <- V.mapM G.thaw m
  m'' <- V.thaw m'
  elim 0 m''
  subst (n-2) m''
  m''' <- V.unsafeFreeze m''
  V.mapM G.unsafeFreeze m'''
  -- V.createT is not available on AtCoder
  where
    !n = V.length m
    elim :: Int -> VM.MVector s (G.Mutable vector s k) -> ST s ()
    elim !i !m
      | i >= n = return ()
      | otherwise = do
          let findK k | k >= n = error "singular matrix"
                      | otherwise = do
                          row <- VM.read m k
                          w <- GM.read row i
                          if w == 0
                            then findK (k + 1)
                            else return (k,row,w)
          (k,rowK,w) <- findK i -- i <= k
          let !r = recip w -- r == recip (m!(k,i))
          forM_ [i..GM.length rowK - 1] $ \j -> do
            GM.modify rowK (\x -> x * r) j
          -- GM.set (GM.take i rowK) 0
          forM_ [i..n-1] $ \i' -> do
            row' <- VM.read m i'
            when (i' /= k) $ do
              y <- GM.read row' i -- m!(i',i)
              let !yy = y
              forM_ [i..GM.length row' - 1] $ \j -> do
                z <- GM.read rowK j
                GM.modify row' (\x -> x - z * yy) j
          VM.swap m i k
          elim (i+1) m
    subst :: Int -> VM.MVector s (G.Mutable vector s k) -> ST s ()
    subst !i !m
      | i < 0 = return ()
      | otherwise = do
          row <- VM.read m i
          let loop !j !x | j >= n = GM.write row n x
                         | otherwise = do
                             c <- GM.read row j
                             y <- VM.read m j >>= (`GM.read` n)
                             loop (j+1) (x - c * y)
          rhs <- GM.read row n
          loop (i + 1) rhs
          -- GM.set (GM.drop (i+1) $ GM.take n row) 0
          subst (i - 1) m
{-
    dump :: VM.MVector s (G.Mutable vector s k) -> ST s ()
    dump m = do m' <- V.freeze m
                fr <- V.mapM G.freeze m'
                traceShow fr $ return ()
-}

---

exEuclid :: (Eq a, Integral a) => a -> a -> (a, a, a)
exEuclid !f !g = loop 1 0 0 1 f g
  where loop !u0 !u1 !v0 !v1 !f 0 = (f, u0, v0)
        loop !u0 !u1 !v0 !v1 !f g =
          case divMod f g of
            (q,r) -> loop u1 (u0 - q * u1) v1 (v0 - q * v1) g r

modulo = 998244353 :: Int
addMod, subMod, mulMod, divM :: Int -> Int -> Int
addMod !x !y = (x + y) `rem` modulo
subMod !x !y = (x - y) `mod` modulo
mulMod !x !y = (x * y) `rem` modulo
recipM :: Int -> Int
recipM !x = case exEuclid x modulo of
             (1,a,_) -> a `mod` modulo
             (-1,a,_) -> (-a) `mod` modulo
divM !x !y = x `mulMod` recipM y

newtype N = N { unwrapN :: Int } deriving (Eq)
instance Show N where
  show (N x) = show x
instance Num N where
  N x + N y = N ((x + y) `rem` modulo)
  N x - N y = N ((x - y) `mod` modulo)
  N x * N y = N ((x * y) `rem` modulo)
  fromInteger n = N (fromInteger (n `mod` fromIntegral modulo))
  abs = undefined; signum = undefined

instance Fractional N where
  N x / N y = N (divM x y)
  recip (N x) = N (recipM x)
  fromRational = undefined

---

newtype instance UM.MVector s N = MV_N (UM.MVector s Int)
newtype instance U.Vector N = V_N (U.Vector Int)

instance Data.Vector.Generic.Mutable.MVector UM.MVector N where -- needs MultiParamTypeClasses here
  basicLength (MV_N mv) = Data.Vector.Generic.Mutable.basicLength mv
  basicUnsafeSlice i l (MV_N mv) = MV_N (Data.Vector.Generic.Mutable.basicUnsafeSlice i l mv)
  basicOverlaps (MV_N mv) (MV_N mv') = Data.Vector.Generic.Mutable.basicOverlaps mv mv'
  basicUnsafeNew l = MV_N <$> Data.Vector.Generic.Mutable.basicUnsafeNew l
  basicInitialize (MV_N mv) = Data.Vector.Generic.Mutable.basicInitialize mv
  basicUnsafeReplicate i x = MV_N <$> Data.Vector.Generic.Mutable.basicUnsafeReplicate i (coerce x)
  basicUnsafeRead (MV_N mv) i = coerce <$> Data.Vector.Generic.Mutable.basicUnsafeRead mv i
  basicUnsafeWrite (MV_N mv) i x = Data.Vector.Generic.Mutable.basicUnsafeWrite mv i (coerce x)
  basicClear (MV_N mv) = Data.Vector.Generic.Mutable.basicClear mv
  basicSet (MV_N mv) x = Data.Vector.Generic.Mutable.basicSet mv (coerce x)
  basicUnsafeCopy (MV_N mv) (MV_N mv') = Data.Vector.Generic.Mutable.basicUnsafeCopy mv mv'
  basicUnsafeMove (MV_N mv) (MV_N mv') = Data.Vector.Generic.Mutable.basicUnsafeMove mv mv'
  basicUnsafeGrow (MV_N mv) n = MV_N <$> Data.Vector.Generic.Mutable.basicUnsafeGrow mv n

instance Data.Vector.Generic.Vector U.Vector N where -- needs MultiParamTypeClasses here
  basicUnsafeFreeze (MV_N mv) = V_N <$> Data.Vector.Generic.basicUnsafeFreeze mv
  basicUnsafeThaw (V_N v) = MV_N <$> Data.Vector.Generic.basicUnsafeThaw v
  basicLength (V_N v) = Data.Vector.Generic.basicLength v
  basicUnsafeSlice i l (V_N v) = V_N (Data.Vector.Generic.basicUnsafeSlice i l v)
  basicUnsafeIndexM (V_N v) i = coerce <$> Data.Vector.Generic.basicUnsafeIndexM v i
  basicUnsafeCopy (MV_N mv) (V_N v) = Data.Vector.Generic.basicUnsafeCopy mv v
  elemseq (V_N v) x y = Data.Vector.Generic.elemseq v (coerce x) y

instance U.Unbox N

unsafeCoerce_UArray_N_Int :: UArray i N -> UArray i Int
unsafeCoerce_UArray_N_Int = Unsafe.Coerce.unsafeCoerce
unsafeCoerce_UArray_Int_N :: UArray i Int -> UArray i N
unsafeCoerce_UArray_Int_N = Unsafe.Coerce.unsafeCoerce

instance Data.Array.Base.IArray UArray N where
  bounds arr = Data.Array.Base.bounds (unsafeCoerce_UArray_N_Int arr)
  numElements arr = Data.Array.Base.numElements (unsafeCoerce_UArray_N_Int arr)
  unsafeArray lu ies = unsafeCoerce_UArray_Int_N $ Data.Array.Base.unsafeArray lu (coerce ies)
  unsafeAt arr i = coerce (Data.Array.Base.unsafeAt (unsafeCoerce_UArray_N_Int arr) i)
  unsafeReplace arr ies = unsafeCoerce_UArray_Int_N (Data.Array.Base.unsafeReplace (unsafeCoerce_UArray_N_Int arr) (coerce ies))
  unsafeAccum f arr ies = unsafeCoerce_UArray_Int_N (Data.Array.Base.unsafeAccum (coerce f) (unsafeCoerce_UArray_N_Int arr) ies)
  unsafeAccumArray f e lu ies = unsafeCoerce_UArray_Int_N (Data.Array.Base.unsafeAccumArray (coerce f) (coerce e) lu ies)