A campus chemistry lab keeps three shelves stocked for a routine synthesis: a catalyst shelf, a reactant shelf, and a solvent shelf. Each shelf holds a list of batch codes (positive integers), and no two batches on the same shelf share a code — but the same numeric code can happen to sit on more than one shelf, since each shelf was numbered independently by whoever restocked it. To run one synthesis you must pick exactly one batch from each shelf to fill the catalyst role, the reactant role, and the solvent role. A single physical batch cannot be poured into two roles at once, so a chosen combination is only usable if the three picked codes are pairwise different. Given the three shelves, list every usable combination.
Line 1: three integers n1 n2 n3 — the number of batches on the catalyst shelf, the reactant shelf, and the solvent shelf. Line 2: n1 integers — the catalyst shelf's batch codes. Line 3: n2 integers — the reactant shelf's batch codes. Line 4: n3 integers — the solvent shelf's batch codes.
Print one line "a b c" for every usable combination, where a is a catalyst code, b is a reactant code, and c is a solvent code, with a, b, c pairwise distinct. Order the lines by a ascending, then by b ascending, then by c ascending. If no usable combination exists, print nothing.
Example 1
Input
2 2 2 1 2 2 3 3 1
Expected
1 2 3 2 3 1
Explanation
The catalyst shelf holds {1,2}, the reactant shelf holds {2,3}, and the solvent shelf holds {3,1}. Checking all 8 combinations: (1,2,3) has three different codes, so it is usable. (1,2,1) reuses code 1 for both catalyst and solvent, so it is rejected, and likewise (1,3,3), (1,3,1), (2,2,3), (2,2,1) and (2,3,3) each reuse a code. Only (2,3,1) besides (1,2,3) survives. Sorted by a then b then c, the output is "1 2 3" followed by "2 3 1".
Example 2
Input
1 1 1 5 5 5
Expected
(empty)Explanation
Every shelf holds only batch 5, so the only possible combination is (5,5,5), which reuses the same batch in all three roles. No usable combination exists, so the program prints nothing.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →