class TrieNode: __slots__ = ['children', 'count'] def __init__(self): self.children = [None, None] self.count = 0 def insert(node, number): for bit in reversed(range(18)): b = (number >> bit) & 1 if not node.children[b]: node.children[b] = TrieNode() node = node.children[b] node.count += 1 def query(node, number, X): count = 0 current = node for bit in reversed(range(18)): if not current: break a_bit = (number >> bit) & 1 x_bit = (X >> bit) & 1 if x_bit: if current.children[a_bit]: count += current.children[a_bit].count current = current.children[1 - a_bit] else: current = current.children[a_bit] return count def main(): import sys input = sys.stdin.read().split() idx = 0 N = int(input[idx]) idx += 1 X = int(input[idx]) idx += 1 A = list(map(int, input[idx:idx+N])) # Compute total_valid_pairs root_total = TrieNode() total_valid = 0 for num in A: total_valid += query(root_total, num, X) insert(root_total, num) ans = 0 for b in range(18): # Filter numbers where the b-th bit is unset S = [] for num in A: if (num & (1 << b)) == 0: S.append(num) # Compute count_both_unset for this bit root = TrieNode() count = 0 for num in S: count += query(root, num, X) insert(root, num) # Add contribution ans += (total_valid - count) * (1 << b) print(ans) if __name__ == "__main__": main()