import bisect def find_kth_smallest(): import sys input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]) idx += 1 K = int(data[idx]) idx += 1 P = int(data[idx]) idx += 1 A = list(map(int, data[idx:idx+N])) idx += N B = list(map(int, data[idx:idx+N])) idx += N B.sort() low = 0 high = P - 1 ans = high while low <= high: mid = (low + high) // 2 total = 0 for s in A: if mid >= s: x = mid - s cnt1 = bisect.bisect_right(B, x) else: cnt1 = 0 lower = P - s upper = mid + P - s upper = min(upper, P - 1) if upper < lower: cnt2 = 0 else: left = bisect.bisect_left(B, lower) right = bisect.bisect_right(B, upper) cnt2 = right - left total += cnt1 + cnt2 if total > K: break if total >= K: ans = mid high = mid - 1 else: low = mid + 1 print(ans) find_kth_smallest()