#include using namespace std; using ll = long long int; using ld = long double; const ll MAX = 5000000000000000000; const ld PI = 3.14159265358979; const ll MOD = 1000000007;//2024948111; random_device rd; mt19937 mt(rd()); ld dotorad(ld K){return PI * K / 180.0;} ld radtodo(ld K){return K * 180.0 / PI;} int main(){ ll N,K,P; cin >> N >> K >> P; vector A(N),B(N); for(ll i = 0;i < N;i++) cin >> A[i]; for(ll i = 0;i < N;i++) cin >> B[i]; sort(A.begin(),A.end()); B.emplace_back(-MAX); B.emplace_back(MAX); sort(B.begin(),B.end()); ll l = P - 1,r = -1; while(l - r > 1){ ll m = (l + r) / 2,c = 0; for(ll i = 0;i < N;i++){ ll a,b; a = (P - 1) - A[i]; b = m - A[i]; ll p = N - (upper_bound(B.begin(),B.end(),a) - B.begin()); ll q = N - (lower_bound(B.begin(),B.end(),b) - B.begin()); a = 2 * P - 1 - A[i]; b = P + m - A[i]; p += N - (upper_bound(B.begin(),B.end(),a) - B.begin()); q += N - (lower_bound(B.begin(),B.end(),b) - B.begin()); c += q - p; } //cout << m << "/" << c << endl; if(c < N * N - K + 1) l = m; else r = m; } cout << r << endl; }