#include //#include //#pragma GCC optimize("Ofast") using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() #define fi first #define se second using ll = long long; using vec = vector; using mat = vector; ll N,M,H,W,Q,K,A,B; string S; typedef pair P; const ll INF = (1LL<<58); template void adamard(vector &a, bool inv){ int n = a.size(); for(int i = 1; i < n; i <<= 1){ int m = n - i; for(int j = 0; j < m; ++j){ j += j&i; T temp = a[j|i]; a[j|i] = a[j] - temp; a[j] += temp; if(inv){ a[j] /= 2; a[j|i] /= 2; } } } } template vector xor_convolution(vector &a, vector &b){ //can_divide ? " / 2" : " * 2.inv()" int n(1); while(n < max((int)a.size(), (int)b.size())) n <<= 1; vector a_cpy(n), b_cpy(n); copy(ALL(a), a_cpy.begin()); copy(ALL(b), b_cpy.begin()); adamard(a_cpy, false); adamard(b_cpy, false); rep(i, n) a_cpy[i] *= b_cpy[i]; adamard(a_cpy, true); return a_cpy; } int main() { const int max_A = 1<<18; cin>>N>>K; vec a(N), cnt(max_A, 0), cnt_cnv; rep(i, N) {cin>>a[i]; ++cnt[a[i]];} cnt_cnv = xor_convolution(cnt, cnt); ll res(-accumulate(ALL(a), 0LL)); for(int n = 1; n < max_A; n <<= 1){ vec cnt_without_bitk(max_A, 0); int r = max_A - n; rep(i, r){ i += i & n; cnt_without_bitk[i] = cnt[i]; } vec cnt_without_bitk_cnv = xor_convolution(cnt_without_bitk, cnt_without_bitk); rep(i, K) res += (cnt_cnv[i] - cnt_without_bitk_cnv[i]) * n; } cout<