先把线性基建出来
显然其他所有数都可以凑成线性基的最大值
考虑怎么让线性基内和最大
手玩一下可以发现最优情况是最高位的都有,剩下每一个基都少填一个
#include<bits/stdc++.h>
using namespace std;
const int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ob==ib)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ob==ib)?EOF:*ib++;
}
#define int long long
#define gc getchar
inline int read(){
char ch=gc();
int res=0,f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
#define ll long long
#define re register
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define cs const
#define bg begin
#define int long long
#define poly vector<int>
cs int mod=1e9+7;
inline int add(int a,int b){return (a+=b)>=mod?a-mod:a;}
inline int dec(int a,int b){return (a-=b)<0?a+mod:a;}
inline int mul(int a,int b){return 1ll*a*b%mod;}
inline void Add(int &a,int b){(a+=b)>=mod?a-=mod:0;}
inline void Dec(int &a,int b){(a-=b)<0?a+=mod:0;}
inline void Mul(int &a,int b){a=1ll*a*b%mod;}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),a);return res;}
inline int Inv(int x){return ksm(x,mod-2);}
inline void chemx(int &a,int b){a<b?a=b:0;}
inline void chemn(int &a,int b){a>b?a=b:0;}
cs int N=55;
int a[N],bas[N],siz,n;
inline void insert(int x){
for(int i=50;~i;i--)
if(x&(1ll<<i)){
if(!bas[i]){bas[i]=x,siz++;break;}
else{
x^=bas[i];
if(!x)return;
}
}
}
signed main(){
n=read();
for(int i=1;i<=n;i++){
a[i]=read();
insert(a[i]);
}
for(int i=50;~i;i--){
for(int j=i-1;~j;j--)
if((bas[i]&(1ll<<j))&&bas[j])bas[i]^=bas[j];
}
int res=0,ans=0;
for(int i=50;~i;i--)if(!(res&(1ll<<i))&&bas[i])res^=bas[i];
ans=(n-siz)*res;
for(int i=50,first=0;~i;i--){
if(bas[i]){
ans+=res^(first*bas[i]);first=1;
}
}
cout<<ans;
}