struct RNG { seed: usize, } impl RNG { fn new(seed: usize) -> Self { RNG { seed: seed, } } fn next(&mut self) -> usize { let x = &mut self.seed; *x = *x ^ (*x << 13); *x = *x ^ (*x >> 7); *x = *x ^ (*x << 17); *x >> 33 } } fn run() { let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let n: usize = it.next().unwrap().parse().unwrap(); let q: usize = it.next().unwrap().parse().unwrap(); let seed: usize = it.next().unwrap().parse().unwrap(); let rng = &mut RNG::new(seed); for _ in 0..10000 { rng.next(); } let sup = 1usize << 31; let m = 1 << 16; let mut a = vec![vec![]; sup / m]; for _ in 0..n { let v: usize = rng.next(); a[v / m].push(v); } let mut cnt = vec![0; sup / m + 1]; for i in (0..(sup / m)).rev() { cnt[i] = cnt[i + 1] + a[i].len(); } let mut ans = 0; for i in 0..q { let x: usize = rng.next(); let mut c = n - cnt[x / m]; for &a in &a[x / m] { if a < x { c += 1; } } ans ^= c * i; } println!("{}", ans); } fn main() { run(); }