Pillars

The world-famous architect Mr. Fruí from Reus plans to build a colossal pillar H units high. Mr. Fruí has n black pieces with heights b1,...,bn and m white pieces with heights w1,...,wm. According to his design the pillar must have four pieces: a black piece on its bottom, a white piece above it, another black piece above, and finally a white piece on the top of the pillar. Mr. Fruí wishes to know which of the combinations of four pieces with total height H is the most stable. Given two combinations A = [a1, a2, a3, a4] and B = [b1, b2, b3, b4] (where a1 denotes the height of the bottom (black) piece of the pillar A, a2 denotes the height of the second (white) piece of A, and soon),AismorestablethanBifa1 >b1,orifa1 =b1 buta2 >b2,etc. (Inotherwords,Aismore stable than B if and only if the sequence of heights of the pieces of A is lexicographically larger than the sequence of heights of the pieces of B.) Write a program such that, given the desired height H of the pillar, the heights of the black pieces and the heights of the white pieces, computes which pillar (if any) of height exactly H would be the most stable. Input Input consists of zero ore more test cases. Each test case has on the first line H, an integer between 1 and 4 ∗ 108. The second and third lines of each test consist respectively of the sequence b1, . . . , bn and of the sequence w1,...,wm. A blank line separates two consecutive test cases. You can assume 2 ≤ n ≤ 100 and 2 ≤ m ≤ 100, and that no piece has a height larger than 108. Output For every test case, print one line with the sequence of heights of the pieces of the most stable pillar. If no solution exists, print ‘no solution’. Sample Input 100 20 20 30 10 30 50 100 20 10 4 50 30 45 Sample Output 20 50 20 10 no solution