import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); long k = sc.nextLong(); int p = sc.nextInt(); int[] aArr = new int[n]; for (int i = 0; i < n; i++) { aArr[i] = sc.nextInt() % p; } Arrays.sort(aArr); int[] bArr = new int[n]; for (int i = 0; i < n; i++) { bArr[i] = sc.nextInt() % p; } Arrays.sort(bArr); int left = 0; int right = p; while (right - left > 1) { int m = (left + right) / 2; int one = n - 1; int zero = n - 1; int two = n - 1; long count = 0; for (int i = 0; i < n; i++) { while (one >= 0 && aArr[i] + bArr[one] >= m) { one--; } count += one + 1; while (zero >= 0 && aArr[i] + bArr[zero] >= p) { zero--; } while (two >= 0 && aArr[i] + bArr[two] >= p + m) { two--; } count += two - zero; } if (count >= k) { right = m; } else { left = m; } } System.out.println(left); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }