#define _USE_MATH_DEFINES #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); } } iosetup; template std::vector convolution_xor(const std::vector &a, const std::vector &b, const T UNITY = 0) { auto fwht = [&](std::vector v) -> std::vector { int n = v.size(), p = 1; while ((1 << p) < n) ++p; n = 1 << p; v.resize(n, UNITY); for (int i = 1; i < n; i <<= 1) for (int j = 0; j < n; ++j) { if ((j & i) == 0) { T tmp1 = v[j], tmp2 = v[j | i]; v[j] = tmp1 + tmp2; v[j | i] = tmp1 - tmp2; } } return v; }; std::vector a_fwht = fwht(a), b_fwht = fwht(b); int n = a_fwht.size(); for (int i = 0; i < n; ++i) a_fwht[i] *= b_fwht[i]; std::vector res = fwht(a_fwht); for (int i = 0; i < n; ++i) res[i] /= n; return res; } int main() { int n, x; cin >> n >> x; vector a(n); REP(i, n) cin >> a[i]; constexpr int B = 18, X = 1 << B; vector b(X, 0); REP(i, n) ++b[a[i]]; b = convolution_xor(b, b); ll pat = -n; REP(i, x) pat += b[i]; pat /= 2; ll ans = 0; REP(bit, B) { b.assign(X, 0); ll sum = 0; REP(i, n) { if (a[i] >> bit & 1) continue; ++b[a[i]]; --sum; } b = convolution_xor(b, b); REP(i, x) sum += b[i]; sum /= 2; ans += (pat - sum) * (1 << bit); } cout << ans << '\n'; return 0; }