PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000304. Tổng trên các mặt nạ con (Subset Zeta Transform)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tổng trên các mặt nạ con (Subset Zeta Transform)

Subset Zeta Transform

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given a nonnegative integer kk and a table ff of 2k2^k integers indexed from 00 through 2k−12^k-1, each index is represented by kk bits corresponding to a subset of a set of kk elements. A bit of 11 indicates membership and a bit of 00 indicates nonmembership.

A mask TT is a submask of SS, written T⊆ST\subseteq S, if every set bit of TT is also set in SS, equivalently (T&S)=T(T\mathbin{\&}S)=T. The empty mask 00 and SS itself are included.

For every mask SS from 00 through 2k−12^k-1, compute the sum of f[T]f[T] over all submasks TT of SS:

g[S]=∑T⊆Sf[T].g[S]=\sum_{T\subseteq S}f[T].

When k=0k=0, only mask 00 exists and g[0]=f[0]g[0]=f[0].

Input

The first line contains an integer kk, the number of bits in each mask.

The second line contains 2k2^k integers f[0],f[1],…,f[2k−1]f[0],f[1],\ldots,f[2^k-1] in increasing mask order.

Output

Print 2k2^k integers on one line in increasing mask order. Do not reduce modulo anything.

Subtasks

  • Subtask 1 (20 points): 0≤k≤50\le k\le5; −109≤f[S]≤109-10^9\le f[S]\le10^9 (for every 0≤S<2k0\le S<2^k).
  • Subtask 2 (30 points): 0≤k≤200\le k\le20; −109≤f[S]≤109-10^9\le f[S]\le10^9 (for every 0≤S<2k0\le S<2^k); all values f[S]f[S] are equal.
  • Subtask 3 (50 points): 0≤k≤200\le k\le20; −109≤f[S]≤109-10^9\le f[S]\le10^9 (for every 0≤S<2k0\le S<2^k).

Example 1

Input

2
2 -1 3 4

Output

2 1 5 8

Explanation

For k=2k=2, masks 0,1,2,30,1,2,3 have binary representations 00,01,10,1100,01,10,11 and f=[2,−1,3,4]f=[2,-1,3,4].

  • g[0]=f[0]=2g[0]=f[0]=2.
  • g[1]=f[0]+f[1]=2−1=1g[1]=f[0]+f[1]=2-1=1.
  • g[2]=f[0]+f[2]=2+3=5g[2]=f[0]+f[2]=2+3=5.
  • g[3]=f[0]+f[1]+f[2]+f[3]=2−1+3+4=8g[3]=f[0]+f[1]+f[2]+f[3]=2-1+3+4=8.

In increasing mask order the result is 2 1 5 8.

Example 2

Input

0
-7

Output

-7

Explanation

With k=0k=0, 2k=12^k=1. Mask 00 is the only mask and its only submask is itself. Thus g[0]=f[0]=−7g[0]=f[0]=-7; print -7.