#include using namespace std; int main(){ int N; long long K; long long P; cin >> N >> K >> P; vector A(N), B(N); for(int i = 0; i < N; i++) cin >> A[i]; for(int i = 0; i < N; i++) cin >> B[i]; sort(A.begin(), A.end()); sort(B.begin(), B.end()); int ub = P, lb = -1; while(ub - lb > 1){ int mid = (ub + lb) / 2; long long cnt = 0; for(int i = 0; i < N; i++){ if(mid < A[i]){ int ind = upper_bound(B.begin(), B.end(), mid + P - A[i]) - lower_bound(B.begin(), B.end(), P - A[i]); cnt += ind; } else{ int ind = upper_bound(B.begin(), B.end(), mid + P - A[i]) - lower_bound(B.begin(), B.end(), P - A[i]); int id = upper_bound(B.begin(), B.end(), mid - A[i]) - B.begin(); cnt += ind; cnt += id; } } if(cnt >= K) ub = mid; else lb = mid; } cout << ub << endl; }