#include // #include using namespace std; // using namespace atcoder; #define DEBUG(x) cerr<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair template pair operator+(const pair &s, const pair &t) { return pair(s.first + t.first, s.second + t.second); } template pair operator-(const pair &s, const pair &t) { return pair(s.first - t.first, s.second - t.second); } template ostream& operator<<(ostream& os, pair p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; #define Sp(p) cout<= 1) { if ((n&m)) { cout << 1; } else { cout << 0; } m >>= 1; } cout << endl; } void solve2(vl a) { if (a.size() <= 1) return; int n = a.size(); rep (i, a.size()) { ans += a[i] * (n - 1); } rep (k, 18) { int mask = 1 << k; ll cnt = 0; rep (i, n) { if (a[i] & mask) cnt++; } ans -= mask * (cnt * (cnt - 1)) / 2; } return; } void solve3(vl b, vl c) { if (b.size() == 0 or c.size() == 0) return; int n = b.size(), m = c.size(); ll sum = 0; rep (i, m) sum += c[i]; rep (i, n) ans += sum + b[i] * m; vl cnts(18); rep (i, m) { rrep (k, 18) { int mask = 1 << k; if (c[i] & mask) cnts[k]++; } } rep (i, n) { rrep (k, 18) { int mask = 1 << k; if (b[i] & mask) { ans -= mask * cnts[k]; } } } } void solve4(vl a, vl b, int k) { if (a.size() == 0 or b.size() == 0) return; if (k == -1) { return solve3(a, b); } int mask = 1 << k; vl a0, a1, b0, b1; rep (i, a.size()) { if (a[i] & mask) a1.push_back(a[i]); else a0.push_back(a[i]); } rep (i, b.size()) { if (b[i] & mask) b1.push_back(b[i]); else b0.push_back(b[i]); } if (x & mask) { solve3(a0, b0); solve3(a1, b1); solve4(a0, b1, k - 1); solve4(a1, b0, k - 1); } else { solve4(a0, b0, k - 1); solve4(a1, b1, k - 1); } } void solve(vl a, int k) { // DEBUG_VEC(a); if (a.size() <= 1) return; if (k == -1) { solve2(a); return; } int mask = 1 << k; vl b, c; rep (i, a.size()) { if (a[i] & mask) b.push_back(a[i]); else c.push_back(a[i]); } if (x & mask) { solve2(c); solve4(b, c, k - 1); solve2(b); } else { solve(b, k - 1); solve(c, k - 1); } } signed main() { fio(); cin >> n >> x; x--; // print_bit(x); // print_bit(133); // print_bit(163); vl a(n); rep (i, n) cin >> a[i]; // rep (i, n) { // vi temp; // rep (j, n) { // if (i == j) continue; // if ((a[i] ^ a[j]) <= x) { // temp.push_back(a[j]); // } // } // DEBUG(a[i]); // DEBUG_VEC(temp); // } solve(a, 17); cout << ans << endl; }