提交时间:2022-08-09 22:13:20
运行 ID: 55188
#include<bits/stdc++.h> #define int long long using namespace std; inline int read(){ int x=0;bool f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=0;ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();} return f?x:-x; } int n,ans,cnt[25]; signed main(){ n=read(); for(int i=1,x;i<=n;i++){ x=read(); for(int j=0;x>=(1<<j);j++)if(x&(1<<j))cnt[j]++; } for(int j=1,now=0;j<=n;ans+=(now*now),j++,now=0)for(int i=0;i<20;i++)if(cnt[i])--cnt[i],now+=(1<<i); cout<<ans<<endl; return 0; }