#include #include #include #include using namespace std; using ll = long long; void input(vector& X) { for (int i = 0; i < X.size(); i++) { cin >> X.at(i); } } ll abs_max(vector X) { ll t = 0; for (int i = 0; i < X.size(); i++) { if (t < abs(X.at(i))) { t = abs(X.at(i)); } } return t; } pair h(ll x, vector G, vector H) { if (x == 0) { if (find(G.begin(), G.end(), 0) != G.end()) { return make_pair(0, H[0]); } else { return make_pair(G[0], 0); } } set F(H.begin(), H.end()); for (auto g : G) { if (g == 0) continue; if (x % g == 0 && F.count(x / g)) { return make_pair(g, x / g); } } return make_pair(-1, -1); } int main() { ll K, L, M, N, S, T; cin >> K >> L >> M >> N >> S; vector A(K), B(L), C(M), D(N); vector U(K * L), V(M * N); vector U_pos(0), U_neg(0); vector V_pos(0), V_neg(0); ll U_positive, U_zero, U_negative; ll V_positive, V_zero, V_negative; ll E_positive, E_zero, E_negative; ll A_abs_max, B_abs_max, C_abs_max, D_abs_max; ll E_abs_max; input(A); input(B); input(C); input(D); A_abs_max = abs_max(A); B_abs_max = abs_max(B); C_abs_max = abs_max(C); D_abs_max = abs_max(D); E_abs_max = A_abs_max * B_abs_max * C_abs_max * D_abs_max; int t; t = 0; for (int w = 0; w < K; w++) { for (int x = 0; x < L; x++) { U.at(t++) = A.at(w) * B.at(x); } } t = 0; for (int y = 0; y < M; y++) { for (int z = 0; z < N; z++) { V.at(t++) = C.at(y) * D.at(z); } } sort(V.begin(), V.end()); for (auto u : U) { if (u > 0) { U_pos.push_back(u); } else if (u < 0) { U_neg.push_back(u); } } for (auto v : V) { if (v > 0) { V_pos.push_back(v); } else if (v < 0) { V_neg.push_back(v); } } sort(U_pos.begin(), U_pos.end()); sort(U_neg.begin(), U_neg.end()); sort(V_pos.begin(), V_pos.end()); sort(V_neg.begin(), V_neg.end()); U_positive = U_pos.size(); U_negative = U_neg.size(); U_zero = K * L - (U_positive + U_negative); V_positive = V_pos.size(); V_negative = V_neg.size(); V_zero = M * N - (V_positive + V_negative); E_positive = U_positive * V_positive + U_negative * V_negative; E_negative = U_positive * V_negative + U_negative * V_positive; E_zero = K * L * M * N - (E_positive + E_negative); ll Left, Right, Z, I; if (S <= E_negative) { Left = -(E_abs_max + 1); Right = 1; while (Right - Left > 1) { T = Left + (Right - Left) / 2; Z = I = 0; for (auto u : U_pos) { while (I < V_negative && u * V_neg.at(I) <= T) I++; Z += I; } I = 0; for (auto v : V_pos) { while (I < U_negative && v * U_neg.at(I) <= T) I++; Z += I; } if (Z >= S) { Right = T; } else { Left = T; } } T = Right; } else if (E_negative + 1 <= S && S <= E_negative + E_zero) { T = 0; } else { Left = 0; Right = (E_abs_max + 1) + 1; while (Right - Left > 1) { T = Left + (Right - Left) / 2; Z = 0; I = V_positive; for (auto u : U_pos) { while (I>0 && u * V_pos.at(I-1) > T) I--; Z += I; } I = 0; for (auto v : V_neg) { while (I < U_negative && v * U_neg.at(U_negative-(I+1)) <= T) I++; Z += I; } if (Z >= S - (E_negative + E_zero)) { Right = T; } else { Left = T; } } T = Right; } ll alpha, beta, a, b, c, d; pair P; P = h(T, U, V); alpha = P.first; beta = P.second; P = h(alpha, A, B); a = P.first; b = P.second; P = h(beta, C, D); c = P.first; d = P.second; cout << T << endl; cout << a << " " << b << " " << c << " " << d << endl; }