/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author aajisaka */ #include using namespace std; void debug_out() { cerr << endl; } template void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr) #define rep(i,n) for(int i=0; i<(int)(n); i++) #define all(v) v.begin(), v.end() template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using ull = unsigned long long; using P = pair; constexpr long double PI = 3.14159265358979323846264338327950288L; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // Fast Walsh-Hadamard transform // Original: https://kazuma8128.hatenablog.com/entry/2018/05/31/144519 // Get C[k] = Sum(A[i]*B[j]) (i^j=k) by O(nlogn) // n must be 2^p (p: non-negative integer) // fwt_xor(A); fwt_xor(B); // rep(i, n) C[i] = A[i]*B[i]; // ifwt_xor(C); template void fwt_xor(vector& f) { int n = f.size(); for (int i = 1; i < n; i <<= 1) { for (int j = 0; j < n; j++) { if ((j & i) == 0) { T x = f[j], y = f[j | i]; f[j] = x + y, f[j | i] = x - y; } } } } template void ifwt_xor(vector& f) { int n = f.size(); for (int i = 1; i < n; i <<= 1) { for (int j = 0; j < n; j++) { if ((j & i) == 0) { T x = f[j], y = f[j | i]; f[j] = (x + y) / 2, f[j | i] = (x - y) / 2; } } } } // Get C[k] = Sum(A[i]*B[j]) (i|j=k) by O(nlogn) // n must be 2^p (p: non-negative integer) // fwt_or(A); fwt_or(B); // rep(i, n) C[i] = A[i]*B[i]; // ifwt_or(C); template void fwt_or(vector& f) { int n = f.size(); for (int i = 1; i < n; i <<= 1) { for (int j = 0; j < n; j++) { if ((j & i) == 0) { f[j | i] += f[j]; } } } } template void ifwt_or(vector& f) { int n = f.size(); for (int i = 1; i < n; i <<= 1) { for (int j = 0; j < n; j++) { if ((j & i) == 0) { f[j | i] -= f[j]; } } } } // Get C[k] = Sum(A[i]*B[j]) (i&j=k) by O(nlogn) // n must be 2^p (p: non-negative integer) // fwt_and(A); fwt_and(B); // rep(i, n) C[i] = A[i]*B[i]; // ifwt_and(C); template void fwt_and(vector& f) { int n = f.size(); for (int i = 1; i < n; i <<= 1) { for (int j = 0; j < n; j++) { if ((j & i) == 0) { f[j] += f[j | i]; } } } } template void ifwt_and(vector& f) { int n = f.size(); for (int i = 1; i < n; i <<= 1) { for (int j = 0; j < n; j++) { if ((j & i) == 0) { f[j] -= f[j | i]; } } } } class No1240OrSumOfXorPair { public: void solve(istream& cin, ostream& cout) { SPEED; int n, x; cin >> n >> x; vector a(n); rep(i, n) { cin >> a[i]; } ll ret = 0; vector A(1<<18); rep(i, n) { A[a[i]]++; } ll cnt = 0; fwt_xor(A); rep(i, 1<<18) { A[i] *= A[i]; } ifwt_xor(A); A[0] -= n; // i == j for(int i=0; i