提交时间:2022-08-09 11:30:55
运行 ID: 55104
#include <bits/stdc++.h> using namespace std; #define LL long long const int N =1e6+10; LL a[N],n; inline LL read() { LL 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; } void Slove() { while(1) { bool falg=false; for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { LL sum1=a[i]&a[j],sum2=a[i]|a[j]; if(pow(sum1,2)+pow(sum2,2)>pow(a[i],2)+pow(a[j],2)) a[i]=sum1,a[j]=sum2; } } if(!falg) break; } } int main() { n=read(); for(int i=1; i<=n; i++) a[i]=read(); Slove(); LL sum=0; for(int i=1; i<=n; i++) sum+=pow(a[i],2); printf("%lld",sum); return 0; }