use std::io::Read; fn run() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); it.next(); let sup: u64 = it.next().unwrap().parse().unwrap(); let mut a: Vec = it.map(|s| s.parse().unwrap()).collect(); a.sort(); let a = a.as_slice(); let calc = |a: &[u64], b: &[u64]| -> u64 { let mut cnt = [0; 18]; for a in a.iter() { for (i, c) in cnt.iter_mut().enumerate() { *c += *a >> i & 1; } } let n = a.len() as u64; let mut sum = 0u64; for b in b.iter() { for (i, c) in cnt.iter().enumerate() { sum += (*c + (n - *c) * (*b >> i & 1)) << i; } } sum }; let mut dfs = vec![(a, a, 20)]; let mut ans = 0u64; while let Some((a, b, k)) = dfs.pop() { if a.is_empty() || b.is_empty() || k == 0 { continue; } let k = k - 1; let x = a.iter().position(|a| *a >> k & 1 == 1).unwrap_or(a.len()); let (al, ar) = a.split_at(x); let y = b.iter().position(|a| *a >> k & 1 == 1).unwrap_or(b.len()); let (bl, br) = b.split_at(y); if sup >> k & 1 == 1 { ans += calc(al, bl); ans += calc(ar, br); dfs.push((al, br, k)); dfs.push((ar, bl, k)); } else { dfs.push((al, bl, k)); dfs.push((ar, br, k)); } } a.iter().for_each(|a| ans -= *a); ans /= 2; println!("{}", ans); } fn main() { run(); }