Under construction

Still being built. Things may change

Convolution

Time limit2sMemory limit1024 MB

Summary
Compute the union convolution H(A) = sum of F(B)G(C) over B union C = A for arrays from a PRNG, then print a weighted checksum mod 2^32.
Level

Medium4 of 10

Topics
Bit manipulation, Math
Solved
No attempts yet

Problem

Consider all subsets of the set U={0,1,2,…,n−1}U = \{0, 1, 2, \dots, n-1\}. Each subset A={a1,a2,…,ak}A = \{a_1, a_2, \dots, a_k\} corresponds to a unique integer p(A)=∑i=1k2aip(A) = \sum_{i=1}^k 2^{a_i}. A function FF on an nn-element set is given by an integer array ff of length 2n2^n, and F(A)=f[p(A)]F(A) = f[p(A)].

You are given two functions FF and GG. Find the function HH such that

H(A)=∑B∪C=AF(B)G(C).H(A) = \sum_{B \cup C = A} F(B)G(C).

Input

The first line contains two integers nn and tt (1≤n≤161 \le n \le 16, 1≤t≤1001 \le t \le 100). Here nn is the size of UU, and tt is the number of test cases.

The second line contains two integers aa and bb, each from 11 to 10910^9. They are used in the following pseudo-random generator:

1. unsigned int cur = 0; // unsigned 32-bit integer
2. unsigned int nextRand16() {
3.   cur = cur * a + b; // calculated modulo 2^32
4.   return cur / 2^16; // integer from 0 to 2^16-1
5. }

The test cases are generated in order. In each one, first generate the elements of ff in increasing index order, then the elements of gg in the same order. Each element is produced by calling nextRand16().

Output

For each test case, print one integer on its own line: (∑AH(A)⋅(p(A)+1)) mod 232\left(\sum_A H(A) \cdot (p(A)+1)\right) \bmod 2^{32}.

Hint

The arrays for the first example are:

  • f1f_1: 3, 113, 3395, 36331, 41370, 61471, 9130, 11774
  • g1g_1: 25547, 45526, 55066, 13590, 14501, 41817, 9356, 18543
  • h1h_1: 76641, 8167827, 273846333, 5284992017, 1656829263, 11450721456, 3699971823, 14260048942
  • f2f_2: 32024, 43238, 51978, 52034, 53714, 38578, 43250, 52338
  • g2g_2: 62834, 50034, 59250, 8050, 44914, 36722, 53106, 20338
  • h2h_2: 2012196016, 6482475400, 8243104152, 15561662464, 7225902008, 16869349792, 22350138288, 44342816072

Examples2

  1. Example 1

    Input
    3 2
    30 239017
    
    Expected output
    2723387430
    3167905008
    
  2. Example 2

    Input
    16 2
    239 17
    
    Expected output
    551267264
    1632349120