Type: Default 1000ms 256MiB

或(hard version)

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Problem Description

给定大小为nn的数组aa,对于每个1≤i≤n1 \le i \le n,输出有多少个j≠ij \ne i,使得ai or aj=aia_{i}\ or\ a_{j} = a_{i}

其中oror代表按位或

Input Format

第一行输入一个整数nn,表示数组大小

第二行输入nn个整数

Output Format

输出nn行,第ii行表示对于ii满足要求的jj的个数

Sample

5
0 1 2 3 4
0
1
1
3
1

Hint

1≤n≤106,0≤ai≤1051 \le n \le 10^{6}, 0 \le a_{i} \le 10^{5}