#include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template constexpr T INF = ::numeric_limits::max() / 32 * 15 + 208; int main() { int a, b, c, d; ll s; cin >> a >> b >> c >> d >> s; vector A(a), B(b), C(c), D(d); for (auto &&i : A) scanf("%d", &i); for (auto &&i : B) scanf("%d", &i); for (auto &&i : C) scanf("%d", &i); for (auto &&i : D) scanf("%d", &i); vector vp, up, vm, um; for (int i = 0; i < a; ++i) { for (int j = 0; j < b; ++j) { if(A[i]*B[j] >= 0) vp.emplace_back(A[i] * B[j]); else vm.emplace_back(A[i] * B[j]); } } for (int i = 0; i < c; ++i) { for (int j = 0; j < d; ++j) { if(C[i]*D[j] >= 0) up.emplace_back(C[i] * D[j]); else um.emplace_back(C[i] * D[j]); } } sort(vp.begin(),vp.end()); sort(vm.begin(),vm.end()); sort(up.begin(),up.end()); sort(um.begin(),um.end()); ll ok = INF, ng = -INF; while(ok-ng > 1){ ll mid = (ok+ng)/2; if([&](ll x) -> bool{ // count v[i]*u[j] <= x ll cnt = 0; if(x >= 0){ cnt += (ll)vp.size()*um.size()+(ll)up.size()*vm.size(); int cur = 0; for (int i = (int)vp.size()-1; i >= 0; --i) { // v >= 0, u >= 0 while(cur < up.size() && up[cur]*vp[i] <= x) cur++; cnt += cur; } cur = um.size(); for (int i = 0; i < vm.size(); ++i) { while(cur > 0 && vm[i]*um[cur-1] <= x) cur--; cnt += um.size()-cur; } }else { int cur = 0; for (int i = (int)vp.size()-1; i >= 0; --i) { while(cur < um.size() && um[cur]*vp[i] <= x) cur++; cnt += cur; } cur = 0; for (int i = (int)vm.size(); i >= 0; --i) { while(cur < up.size() && up[cur]*vm[i] <= x) cur++; cnt += cur; } } return cnt >= s; }(mid)) ok = mid; else ng = mid; } cout << ok << "\n"; // 復元いる? ll ab = 0, cd = 0; [&](ll x) -> void { // count v[i]*u[j] <= x ll cnt = 0; if(x >= 0){ cnt += (ll)vp.size()*um.size()+(ll)up.size()*vm.size(); int cur = 0; for (int i = (int)vp.size()-1; i >= 0; --i) { // v >= 0, u >= 0 while(cur < up.size() && up[cur]*vp[i] < x) cur++; if(cur < up.size() && up[cur]*vp[i] == x) ab = up[cur], cd = vp[i]; } cur = um.size(); for (int i = 0; i < vm.size(); ++i) { while(cur > 0 && vm[i]*um[cur-1] < x) cur--; if(cur > 0 && vm[i]*um[cur-1] == x) ab = vm[i], cd = um[cur-1]; } }else { int cur = 0; for (int i = (int)vp.size()-1; i >= 0; --i) { while(cur < um.size() && um[cur]*vp[i] < x) cur++; if(cur < um.size() && um[cur]*vp[i] == x) ab = vp[i], cd = um[cur]; } cur = 0; for (int i = (int)vm.size(); i >= 0; --i) { while(cur < up.size() && up[cur]*vm[i] < x) cur++; if(cur < up.size() && up[cur]*vm[i] == x) ab = vp[cur], cd = vm[i]; } } }(ok); for (int i = 0; i < a; ++i) { for (int j = 0; j < b; ++j) { if(A[i]*B[j] == ab){ cout << A[i] << " " << B[j] << " "; i = a; j = b; } } } for (int i = 0; i < c; ++i) { for (int j = 0; j < d; ++j) { if(C[i]*D[j] == cd){ cout << C[i] << " " << D[j] << "\n"; i = c; j = d; } } } return 0; }