import java.io.PrintWriter import java.util.* import kotlin.math.* fun modpow(a: Long, e: Long, m: Long): Long { if (e == 0L) return 1 % m if (e == 1L) return a % m val b = modpow(a, e / 2, m) if (e % 2 == 0L) return b * b % m else return (b * b % m) * a % m } fun PrintWriter.solve() { val n = nextInt() val k = nextLong() val m = nextLong() val p = Array(n) { nextLong() } val e = Array(n) { nextLong() } val a = Array(n) { nextLong() } val h = Array(n) { nextLong() } p.sort() e.sort() a.sort() h.sort() var ans = 0L for (i in 0 until n) { val arr = arrayOf(p[i], e[i], a[i], h[i]) val d = arr.max()!! - arr.min()!! ans += modpow(d, k, m) ans %= m } println(ans) } fun main() { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine()!! fun nextDouble() = next().toDouble() // endregion