cho.sh
Notes
Loading...

Gloves

Time limit

2s

Memory limit

128 MB

Problem

There are gloves in N colors. Left-hand gloves are in the left bin, right-hand gloves are in the right bin, and the number of gloves of each color is known. The basement is dark, so the colors of the gloves drawn from a bin cannot be chosen.

For counts x and y, say that the pair (x, y) is guaranteed if every possible selection of x left-hand gloves and y right-hand gloves contains at least one matching color with one left-hand glove and one right-hand glove.

Find a guaranteed pair with minimum x + y. If multiple pairs have the same minimum sum, output the one with the smallest x.

Input

The first line contains the number of colors N (1 <= N <= 20).

The second line contains L_1, L_2, ..., L_N, the number of left-hand gloves of each color in the left bin.

The third line contains R_1, R_2, ..., R_N, the number of right-hand gloves of each color in the right bin.

Every glove count is an integer between 0 and 10^8, inclusive. The input is guaranteed to have at least one valid guaranteed pair.

Output

Print the chosen number x of left-hand gloves and the chosen number y of right-hand gloves, each on its own line.

Notes

The guarantee is judged in the worst case. If some set of colors can provide x left-hand gloves, and the remaining colors can provide y right-hand gloves, then it is possible to avoid a matching pair, so (x, y) is not guaranteed.