fn power(base: usize, times: usize, MOD: usize) -> usize { if times == 0 { return 1usize % MOD; } if times == 1 { return base % MOD; } let temp = power(base, times/2, MOD); temp * temp % MOD * power(base, times%2, MOD) % MOD } fn main() { let mut nkm = String::new(); std::io::stdin().read_line(&mut nkm).ok(); let nkm: Vec = nkm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nkm[0]; let k = nkm[1]; let MOD = nkm[2]; let mut p = String::new(); std::io::stdin().read_line(&mut p).ok(); let mut p: Vec = p.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut e = String::new(); std::io::stdin().read_line(&mut e).ok(); let mut e: Vec = e.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let mut a: Vec = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut h = String::new(); std::io::stdin().read_line(&mut h).ok(); let mut h: Vec = h.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); p.sort(); e.sort(); a.sort(); h.sort(); let result = (0..n).map(|i| p[i].max(e[i]).max(a[i]).max(h[i]) - p[i].min(e[i]).min(a[i]).min(h[i])).map(|v| power(v, k, MOD)).sum::() % MOD; println!("{}", result); }