Under construction

Still being built. Things may change

All Pairs Similarity

Time limit2sMemory limit2048 MB

Summary
Given N bitstrings of length K, output for each cow the sum of its Jaccard similarities with all N bitstrings, including its own, modulo 10^9+7.
Level

Medium7 of 10

Topics
Bit manipulation, Dynamic programming, Math
Solved
No attempts yet

Problem

Farmer John has NN cows (1≤N≤5⋅1051\le N\le 5\cdot 10^5), and each cow is assigned a bitstring of length KK that is not all zero (1≤K≤201\le K\le 20). Different cows may be assigned the same bitstring. The Jaccard similarity of two bitstrings is the number of set bits in their bitwise intersection divided by the number of set bits in their bitwise union. For example, the Jaccard similarity of the bitstrings 11001 and 11010 is 2/42/4. For each cow, output the sum of her bitstring's Jaccard similarity with the bitstrings of all NN cows, including her own, modulo 109+710^9+7. If the sum equals a rational number a/ba/b with aa and bb coprime, output the unique integer xx in [0,109+7)[0, 10^9+7) such that bx−abx-a is divisible by 109+710^9+7.

Input

The first line contains NN and KK. Each of the next NN lines contains an integer i∈(0,2K)i \in (0, 2^K), which represents the cow's bitstring as the length-KK binary representation of ii.

Output

Output the sum modulo 109+710^9+7 for each cow on a separate line.

Hint

The cows are assigned the bitstrings 01, 01, 10, and 11. For the first cow, the sum is sim(1,1)+sim(1,1)+sim(1,2)+sim(1,3)=1+1+0+12≡500000006(mod109+7)\text{sim}(1,1)+\text{sim}(1,1)+\text{sim}(1,2)+\text{sim}(1,3)=1+1+0+\frac{1}{2}\equiv 500000006 \pmod{10^9+7}. The second cow has the same bitstring as the first cow, so her sum is the same. For the third cow, the sum is sim(2,1)+sim(2,1)+sim(2,2)+sim(2,3)=0+0+1+12≡500000005(mod109+7)\text{sim}(2,1)+\text{sim}(2,1)+\text{sim}(2,2)+\text{sim}(2,3)=0+0+1+\frac{1}{2}\equiv 500000005 \pmod{10^9+7}.

Examples1

  1. Example 1

    Input
    4 2
    1
    1
    2
    3
    
    Expected output
    500000006
    500000006
    500000005
    500000006