cswork / OAOpen practice workspace

MicrosoftOA #2

Smallest Missing Positive after Merging A and B

Estimated MediumJudge-ready

Topics (AI-labelled)Hashing

At each position choose either A[i] or B[i] to form C, so that the smallest missing positive integer of C is as small as possible. This site judges by "minimize the missing value"; the original site described it as a number that cannot appear in any C, which contradicts its examples.

Input

The first line contains N (1..100000), the second line contains A, and the third line contains B, each with N integers in 1..100000.

Output

Output a single integer, the answer.

Example 1

Input:

4
1 2 4 3
1 3 2 3

Output:

2

Example 2

Input:

5
3 2 1 6 5
4 2 1 3 3

Output:

3

Example 3

Input:

2
1 2
1 2

Output:

3

Example notes

Example 1: 1 and 3 are forced to appear by fixed positions, while 2 can be avoided; the answer is 2.

Example 2: 1 and 2 are forced to appear, and 3 can be avoided at every position; the answer is 3.

Example 3: the two positions can only pick 1 and 2, so the smallest missing number is 3.

Editorial

Loading solution…