import sys input = sys.stdin.readline def fwht(a): n = len(a) j = 1 while j < n: for i in range(0, n): if i & j == 0: a[i], a[i | j] = a[i] + a[i | j], a[i] - a[i | j] j <<= 1 return a def ifwht(a): n = len(a) j = 1 while j < n: for i in range(0, n): if i & j == 0: a[i], a[i | j] = (a[i] + a[i | j]) >> 1, (a[i] - a[i | j]) >> 1 j <<= 1 return a n, x = map(int, input().split()) assert 2 <= n <= 200000 assert 1 <= x <= 2**18 a = [*map(int, input().split())] assert len(a) == n for i in a: assert 0 <= i < 2**18 cnt = [0] * 2**18 for i in a: cnt[i] += 1 # XOR 畳み込み fwht(cnt) for i in range(2**18): cnt[i] **= 2 ifwht(cnt) ans = 0 for i in range(x): ans += cnt[i] // 2 * i # x OR y == x XOR y + x AND y より, 残りの x AND y を bit ごとに足す for j in range(18): bit = 1 << j cnt = [0] * 2**18 s = 0 for i in a: if i & bit: cnt[i] += 1 s -= 1 # XOR 畳み込み fwht(cnt) for i in range(2**18): cnt[i] **= 2 ifwht(cnt) s += sum(cnt[:x]) ans += s // 2 * bit print(ans)