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

#PS0000303. Đếm tập con theo AND (And Subset Count)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm tập con theo AND (And Subset Count)

And Subset Count

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

Given an array a1,a2,…,ana_1,a_2,\ldots,a_n of nn nonnegative integers, a selection is a nonempty subset of indices I⊆{1,2,…,n}I\subseteq\{1,2,\ldots,n\}. Its value is the bitwise AND of all entries aia_i with i∈Ii\in I. For a single selected index, its value is that entry itself.

Selections are different when their index sets differ, even if the selected values coincide.

For each integer kk from 00 through nn, count selections whose value is exactly kk. Report each count modulo 109+710^9+7.

Input

The first line contains an integer nn, the length of the array.

The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n in index order from 11 to nn.

Output

Print n+1n+1 integers on one line in order k=0,1,…,nk=0,1,\ldots,n, each reduced modulo 109+710^9+7.

Subtasks

  • Subtask 1 (20 points): 1≤n≤151\le n\le15; 0≤ai≤n0\le a_i\le n (for every 1≤i≤n1\le i\le n).
  • Subtask 2 (30 points): 1≤n≤2000001\le n\le200000; 0≤ai≤min⁡(n,15)0\le a_i\le\min(n,15) (for every 1≤i≤n1\le i\le n).
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le200000; 0≤ai≤n0\le a_i\le n (for every 1≤i≤n1\le i\le n).

Example 1

Input

4
3 1 3 4

Output

7 4 0 3 1

Explanation

Here n=4n=4 and the array is 3,1,3,43,1,3,4, giving 24−1=152^4-1=15 nonempty index subsets.

  • Select from positions 1,31,3, both equal to 33: 22−1=32^2-1=3 choices give AND 33.
  • Select position 22 (value 11), exclude position 44, and optionally select positions 1,31,3: 22=42^2=4 choices give AND 11.
  • Select only position 44: one choice gives AND 44.
  • Select position 44 and at least one of the other three positions: 23−1=72^3-1=7 choices give AND 00, since 44 shares no set bit with 11 or 33.

No selection gives AND 22. The counts sum to 7+4+0+3+1=157+4+0+3+1=15, so print 7 4 0 3 1.