#include<bits/stdc++.h>#define int long long#define pii pair<int, int>#define pb push_back#define mk make_pair#define F first#define S second#define ALL(x) x.begin(), x.end()usingnamespacestd;constintINF=2e18;constintmaxn=1e6+5;constintM=1e9+7;intn;inta[maxn];vector<int>build(){vector<int>f((1LL<<21)+1);for(inti=0;i<n;i++){f[a[i]]=(f[a[i]]+1)%M;}for(inti=0;i<21;i++){for(intmask=(1LL<<21)-1;mask>=0;mask--){if(!(mask&(1<<i))){f[mask]=(f[mask]+f[mask^(1<<i)])%M;}}}returnf;}intfpow(inta,intb){intret=1;while(b!=0){if(b&1)ret=(ret*a)%M;a=(a*a)%M;b>>=1;}returnret;}signedmain(){cin>>n;for(inti=0;i<n;i++){cin>>a[i];}vector<int>f=build();intans=0;for(inti=0;i<(1<<21);i++){if(__builtin_popcount(i)&1){ans=((ans-(fpow(2,f[i])-1))%M+M)%M;}else{ans=((ans+(fpow(2,f[i])-1))%M+M)%M;}}cout<<ans<<'\n';}
#include<bits/stdc++.h>#define int long long#define pii pair<int, int>#define pb push_back#define mk make_pair#define F first#define S second#define ALL(x) x.begin(), x.end()usingnamespacestd;constintINF=2e18;constintmaxn=1e6+5;constintM=1e9+7;constintC=(1LL<<21)-1;intn;inta[maxn];piisec(piip,intx){if(x>p.F){p.S=p.F;p.F=x;}elseif(x>p.S){p.S=x;}returnp;}vector<pii>build(){vector<pii>f(C+1,{-1,-1});for(inti=0;i<n;i++){f[C^a[i]]=sec(f[C^a[i]],i);}for(inti=0;i<21;i++){for(intmask=0;mask<(1<<21);mask++){if(mask&(1<<i)){f[mask]=sec(f[mask],f[mask^(1<<i)].F);f[mask]=sec(f[mask],f[mask^(1<<i)].S);}}}vector<pii>d(C+1);for(intmask=0;mask<(1<<21);mask++){d[mask]=f[C^mask];}returnd;}signedmain(){cin>>n;for(inti=0;i<n;i++){cin>>a[i];}vector<pii>dp=build();intans=0;for(inti=0;i<n-2;i++){intres=0,ret=0;for(intj=20;j>=0;j--){if(a[i]&(1<<j)){res|=(1<<j);continue;}else{if(dp[ret|(1<<j)].S>i){ret|=(1<<j);res|=(1<<j);}}}ans=max(ans,res);}cout<<ans<<'\n';}
#include<bits/stdc++.h>#define int long long#define pii pair<int, int>#define pb push_back#define mk make_pair#define F first#define S second#define ALL(x) x.begin(), x.end()usingnamespacestd;constintINF=2e18;constintmaxn=(1<<20)+1;constintM=1e9+7;strings;intn,q;intf[maxn],g[maxn];voidbuild(){for(inti=0;i<(1<<n);i++){f[i]+=s[i]-'0';g[i]+=s[i]-'0';}for(inti=0;i<n;i++){for(intmask=0;mask<(1<<n);mask++){if(mask&(1<<i)){f[mask]+=f[mask^(1<<i)];}}}for(inti=0;i<n;i++){for(intmask=(1<<n)-1;mask>=0;mask--){if(!(mask&(1<<i))){g[mask]+=g[mask^(1<<i)];}}}}intsolver(stringt){intcntq=0,maskq=0,cnt0=0,mask0=0,cnt1=0,mask1=0;for(inti=0;i<n;i++){if(t[i]=='?'){maskq|=(1<<(n-i-1));cntq++;}elseif(t[i]=='0'){mask0|=(1<<(n-i-1));cnt0++;}elseif(t[i]=='1'){mask1|=(1<<(n-i-1));cnt1++;}}intans=0;if(cntq<=6){intmask=0;for(inti=0;i<n;i++){if(t[i]=='1')mask|=(1<<(n-i-1));}ans=s[mask]-'0';for(intS=maskq;S;S=(S-1)&maskq){ans+=s[S|mask]-'0';}}elseif(cnt0<=6){intmask=0;for(inti=0;i<n;i++){if(t[i]=='1')mask|=(1<<(n-i-1));}ans=g[mask];for(intS=mask0;S;S=(S-1)&mask0){if(__builtin_popcountll(S)&1){ans-=g[S|mask];}else{ans+=g[S|mask];}}}elseif(cnt1<=6){intmask=0;for(inti=0;i<n;i++){if(t[i]=='1'||t[i]=='?')mask|=(1<<(n-i-1));}ans=f[mask];for(intS=mask1;S;S=(S-1)&mask1){if(__builtin_popcountll(S)&1){ans-=f[mask^S];}else{ans+=f[mask^S];}}}returnans;}signedmain(){cin>>n>>q;cin>>s;build();while(q--){stringt;cin>>t;cout<<solver(t)<<'\n';}}