#include using namespace std; using ll = long long; ll solve() { ll N, K, 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()); auto get_le = [&](ll x) -> ll { ll s = 0; for ( int i = 0; i < N; i++ ) { s += upper_bound(B.begin(), B.end(), x-A[i]) - lower_bound(B.begin(), B.end(), -A[i]); s += upper_bound(B.begin(), B.end(), P+x-A[i]) - lower_bound(B.begin(), B.end(), P-A[i]); } return s; }; // 単調非減少関数f(x), x:定義域[l,r), 戻り値は [l,r] // y <= f(x) となる最小のx auto lower_bound_f = [](ll l, ll r, ll y, auto f) -> ll { l--; while ( r-l > 1 ) { ll m = l + (r-l)/2; ll fx = f(m); if ( y <= fx ) r = m; else l = m; } return r; }; ll ans = lower_bound_f(0,P,K,get_le); return ans; } int main() { auto ans = solve(); cout << ans << "\n"; return 0; }