import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } enum E = 18; void hadamard(long[] fs) { foreach (e; 0 .. E) { foreach (p; 0 .. 1 << E) { if (!(p & 1 << e)) { const tmp = fs[p] - fs[p | 1 << e]; fs[p] += fs[p | 1 << e]; fs[p | 1 << e] = tmp; } } } } void main() { try { for (; ; ) { const N = readInt(); const X = readInt(); auto A = new int[N]; foreach (i; 0 .. N) { A[i] = readInt(); } auto fs0 = new long[1 << E]; auto fs1 = new long[1 << E]; foreach (i; 0 .. N) { fs0[A[i]] += 1; fs1[A[i]] += A[i]; } fs0.hadamard; fs1.hadamard; auto gs0 = new long[1 << E]; auto gs1 = new long[1 << E]; foreach (h; 0 .. 1 << E) { gs0[h] = fs0[h]^^2; gs1[h] = fs0[h] * fs1[h]; } gs0.hadamard; gs1.hadamard; gs0[] /= 1 << E; gs1[] /= 1 << E; debug { writeln("gs0 = ", gs0[0 .. 1 << 4]); writeln("gs1 = ", gs1[0 .. 1 << 4]); } long ans; // or = (xor + sum) / 2 foreach (h; 0 .. 1 << E) { if (h < X) { ans += gs0[h] * h; ans += gs1[h]; ans += gs1[h]; } } ans /= 2; foreach (i; 0 .. N) { if ((A[i] ^ A[i]) < X) { ans -= A[i] | A[i]; } } ans /= 2; writeln(ans); } } catch (EOFException e) { } }