Jzzhu and Numbers
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Jzzhu have n non-negative integers a1, a2, ..., an. We will call a sequence of indexes i1, i2, ..., ik (1 ≤ i1 < i2 < ... < ik ≤ n) a group of size k.

Jzzhu wonders, how many groups exists such that ai1 & ai2 & ... & aik = 0 (1 ≤ k ≤ n)? Help him and print this number modulo1000000007 (109 + 7). Operation x & y denotes bitwise AND operation of two numbers.

Input

The first line contains a single integer n (1 ≤ n ≤ 106). The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 106).

Output

Output a single integer representing the number of required groups modulo 1000000007 (109 + 7).

Examples
input
3
2 3 3
output
0
input
4
0 1 2 3
output
10
input
6
5 2 0 5 2 1
output
53
分析:暴力肯定不行了,考虑容斥;
   答案为ans=Σ(-1)pow(2,num[x]),f(x)代表x中二进制1的个数,num[x]代表a[k]&x=x的个数;
   求num[x]=Σcnt[k](a[k]&x=x),即为高维前缀和,与spoj tle类似;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=1e6+;
const int N=2e2+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t,num[<<];
ll dp[<<],p[maxn];
int main()
{
int i,j;
p[]=;
rep(i,,maxn-)p[i]=p[i-]*%mod;
scanf("%d",&n);
rep(i,,n)scanf("%d",&j),dp[j]++;
rep(i,,)
{
rep(j,,(<<)-)
{
if((~j)&(<<i))(dp[j]+=dp[j^(<<i)])%=mod;
if(j&(<<i))num[j]++;
}
}
ll ret=;
rep(i,,(<<)-)
{
if(num[i]&)ret=(ret-p[dp[i]]+mod)%mod;
else ret=(ret+p[dp[i]])%mod;
}
printf("%lld\n",ret);
return ;
}
05-17 11:07