## Baltic OI '08 P6 - Gloves

View as PDF

Points: 17 (partial)
Time limit: 1.0s
Memory limit: 32M

Problem types
##### Baltic Olympiad in Informatics: 2008 Day 2, Problem 3

In the dark basement of chemistry professor Acidrain's house there are two drawers with gloves — one with left hand and other with right hand gloves. In each of them there are gloves of different colours. Professor knows how many gloves of each colour there are in each drawer (the number of gloves of the same colour may differ in both drawers). He is also sure that it is possible to find a pair of gloves of the same colour.

Professor's experiment may be successful only if he uses gloves of the same colour (it does not matter which one), so before every experiment he goes to the basement and takes gloves from the drawers hoping that there will be at least one pair of the same colour. It is so dark in the basement that there is no possibility to recognize colour of any glove without going out of the basement. Professor hates going to the basement more than once (in case there was no pair of gloves of the same colour), as well as bringing unnecessarily large amounts of gloves to the laboratory.

Calculate the smallest total number of gloves which must be taken to be sure that among them it is possible to find at least one pair of gloves of the same colour (it is necessary to specify the exact number of gloves to be taken from each drawer).

#### Input Specification

The first line of the standard input contains one positive integer describing the number of distinct colours. The second line of input contains space-separated integers , where corresponds to the number of gloves of colour number in the drawer with left hand gloves. Finally, the third line of input contains space-separated integers , where corresponds to the number of gloves of colour number in the drawer with right hand gloves.

#### Output Specification

The first line of the output should contain an integer — the number of gloves which must be taken from the drawer with left hand gloves. The second line of output should contain an integer — the number of gloves which must be taken from the drawer with right hand gloves. The sum of these two numbers should be as small as possible. If there are several correct results, your program should output any of them.

#### Sample Input

4
0 7 1 6
1 5 0 6

#### Sample Output

2
8

#### Explanation

By taking gloves from the left drawer, he is guaranteed to at least have one of colours or . By taking gloves from the right hand drawer, he is guaranteed to have at least one glove of colour and .