提交时间:2022-08-09 11:30:18
运行 ID: 55098
#include<bits/stdc++.h> using namespace std; #define ull unsigned long long inline ull read() { ull 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; ull a[200010]; ull d,t,ans; int main() { // freopen("jb.in","r",stdin); // freopen("jb.out","w",stdout); n=read(); for(int i=1; i<=n; i++) a[i]=read(); for(int i=1; i<=n; i++) for(int j=i+1; j<=n; j++) { d=(a[i]&a[j]),t=(a[i]|a[j]); if((d*d+t*t)>(a[i]*a[i]+a[j]*a[j])) a[i]=d,a[j]=t; } for(int i=1; i<=n; i++) ans+=a[i]*a[i]; cout<<ans<<endl; return 0; }