import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = Integer.parseInt(sc.next()); long K = Long.parseLong(sc.next()); int P = Integer.parseInt(sc.next()); int[] A = new int[N]; for ( int i = 0 ; i < N ; i++ ) { A[i] = Integer.parseInt(sc.next()); } int[] B = new int[N]; for ( int i = 0 ; i < N ; i++ ) { B[i] = Integer.parseInt(sc.next()); } sc.close(); Arrays.sort(B); int min = 0; int max = P - 1; while ( max - min > 1 ) { int mid = (min + max) / 2; if ( count(A, B, mid, P) < K ) { min = mid; } else { max = mid; } } System.out.println(min); } static long count(int[] A, int[] B, int x, int P) { long cnt = 0; for ( int a : A ) { // 0 == x, P == x + P cnt += count(B, x - a); cnt += count(B, x + P - a) - count(B, P - a); } return cnt; } static long count(int[] B, int x) { if ( B[0] >= x ) { return 0; } else if ( B[B.length - 1] < x ) { return B.length; } int min = 0; int max = B.length - 1; while ( max - min > 1 ) { int mid = (min + max) / 2; if ( B[mid] < x ) { min = mid; } else { max = mid; } } return min + 1; } }