提交时间:2022-08-09 11:31:16
运行 ID: 55109
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int Maxn=200005; inline int read() { int x=0; char c=getchar(); for(; c<'0' || c>'9'; c=getchar()); for(; c<='9' && c>='0'; c=getchar()) x=(x<<3)+(x<<1)+c-'0'; return x; } int n; ll a[Maxn],num[Maxn]; ll sum=0; //inline int Popcnt(int x) //{ // int cnt=0; // for(;x;cnt++) // x-=x&(-x); // return cnt; //} int main() { //freopen("basis4.in","r",stdin); //freopen("ans.txt","w",stdout); n=read(); for(int i=1;i<=n;i++) a[i]=read(); while(1) { bool c=0; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { ll rec1=a[i]&a[j],rec2=a[i]|a[j]; if(a[i]*a[i]+a[j]*a[j]<rec1*rec1+rec2*rec2) { c=1; a[i]=rec1,a[j]=rec2; } } if(!c) break; } for(int i=1;i<=n;i++) sum+=a[i]*a[i]; printf("%lld\n",sum); return 0; }