import bisect from collections import defaultdict def main(): import sys input = sys.stdin.read().split() ptr = 0 K = int(input[ptr]) ptr += 1 L = int(input[ptr]) ptr += 1 M = int(input[ptr]) ptr += 1 N = int(input[ptr]) ptr += 1 S = int(input[ptr]) ptr += 1 A = list(map(int, input[ptr:ptr+K])) ptr += K B = list(map(int, input[ptr:ptr+L])) ptr += L C = list(map(int, input[ptr:ptr+M])) ptr += M D = list(map(int, input[ptr:ptr+N])) ptr += N # Compute AB and ab_dict AB = [] ab_dict = defaultdict(list) for a in A: for b in B: product = a * b AB.append(product) ab_dict[product].append((a, b)) AB.sort() # Compute CD and cd_dict CD = [] cd_dict = defaultdict(list) for c in C: for d in D: product = c * d CD.append(product) cd_dict[product].append((c, d)) CD.sort() # Function to count pairs (ab, cd) where ab*cd <= T def count_pairs(T): count = 0 for ab in AB: if ab == 0: if T >= 0: count += len(CD) else: if ab > 0: required = T / ab cnt = bisect.bisect_right(CD, required) count += cnt else: required = T / ab cnt = len(CD) - bisect.bisect_left(CD, required) count += cnt return count # Determine initial low and high ab_min = min(AB) ab_max = max(AB) cd_min = min(CD) cd_max = max(CD) candidates = [ ab_min * cd_min, ab_min * cd_max, ab_max * cd_min, ab_max * cd_max ] low = min(candidates) high = max(candidates) # Binary search for T while low < high: mid = (low + high) // 2 cnt = count_pairs(mid) if cnt >= S: high = mid else: low = mid + 1 T = low # Find a and b from AB, c and d from CD such that ab * cd == T success = False for ab in AB: if ab == 0: if T == 0: cd = CD[0] a, b = ab_dict[ab][0] c, d = cd_dict[cd][0] print(T) print(a, b, c, d) success = True break else: if T % ab == 0: required_cd = T // ab idx = bisect.bisect_left(CD, required_cd) if idx < len(CD) and CD[idx] == required_cd: a, b = ab_dict[ab][0] c, d = cd_dict[required_cd][0] print(T) print(a, b, c, d) success = True break if not success: pass if __name__ == "__main__": main()