#include using namespace std; #define int long long #define ii pair #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define x first #define y second #define Time (double)clock()/CLOCKS_PER_SEC #define debug(x) std::cout << #x << ": " << x << '\n'; #define FOR(i, n) for (int i = 0; i < n; ++i) #define pb push_back #define trav(a, x) for (auto& a : x) using vi = vector; template std::ostream& operator <<(std::ostream& output, const pair & data) { output << "(" << data.x << "," << data.y << ")"; return output; } template std::ostream& operator <<(std::ostream& output, const std::vector& data) { for (const T& x : data) output << x << " "; return output; } ll div_up(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up ll div_down(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down #define tcT template using V = vector; tcT> void re(V& x) { trav(a, x) cin >> a; } tcT> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } // set a = min(a,b) tcT> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); #endif vi sz(4); FOR (i, 4) cin >> sz[i]; int k; cin >> k; V a(4); FOR (i, 4) { a[i].resize(sz[i]); re(a[i]); } V l, r; vi lv, rv; trav (i, a[0]) trav (j, a[1]) { l.app({i * j, i, j}); lv.app(i * j); } sort(all(l)); sort(all(lv)); vi lv_rev = lv; reverse(all(lv_rev)); trav (i, a[2]) trav (j, a[3]) { r.app({i * j, i, j}); rv.app(i * j); } sort(all(r)); sort(all(rv)); const int INF = 2e18; auto get_left = [&] (V &a, int x) { vi key = {x, INF, INF}; return upper_bound(all(a), key) - a.begin(); }; auto get_right = [&] (V &a, int x) { return (int)a.size() - get_left(a, x - 1); }; auto cnt = [&] (int x) { //prod <= x int ans = 0; trav (a, lv) { if (a == 0) { ans += rv.size(); } } if (x >= 0) { int ptr = 0; trav (a, lv_rev) { if (a < 0) { while (ptr < rv.size() && a * rv[ptr] > x) { ptr++; } ans += (int)rv.size() - ptr; } } } else { int ptr = 0; trav (a, lv) { if (a < 0) { while (ptr < rv.size() && a * rv[ptr] > x) { ptr++; } ans += (int)rv.size() - ptr; } } } if (x >= 0) { int ptr = 0; trav (a, lv_rev) { if (a > 0) { while (ptr < rv.size() && a * rv[ptr] <= x) { ptr++; } ans += ptr; } } } else { int ptr = 0; trav (a, lv) { if (a > 0) { while (ptr < rv.size() && a * rv[ptr] <= x) { ptr++; } ans += ptr; } } } /* trav (v, l) { int a = v[0]; if (a == 0) { if (0 <= x) ans += r.size(); } else if (a < 0) { //a * b <= x //b >= x/a ans += get_right(r, div_up(x, a)); } else { //b <= x/a ans += get_left(r, div_down(x, a)); } } */ return ans; }; int ans; { int l = -INF, r = INF; // l < ans while (l < r - 1) { int m = (l + r) >> 1; if (cnt(m) < k) l = m; else r = m; } ans = r; cout << r << endl; } #ifdef HOME debug(Time); #endif trav (v, l) { int a = v[0]; if (ans == 0 && a == 0) { auto vv = r[0]; cout << v[1] << ' ' << v[2] << ' ' << vv[1] << ' ' << vv[2] << endl; exit(0); } if (a && ans % a == 0) { int b = ans/a; vi key = {b, -INF, -INF}; auto t = lower_bound(all(r), key); if (t != r.end() && (*t)[0] == b) { auto vv = *t; cout << v[1] << ' ' << v[2] << ' ' << vv[1] << ' ' << vv[2] << endl; exit(0); } } } assert(0); }