Preparando MOJI

Complicated Computations

1000ms 262144K

Description:

In this problem MEX of a certain array is the smallest positive integer not contained in this array.

Everyone knows this definition, including Lesha. But Lesha loves MEX, so he comes up with a new problem involving MEX every day, including today.

You are given an array $$$a$$$ of length $$$n$$$. Lesha considers all the non-empty subarrays of the initial array and computes MEX for each of them. Then Lesha computes MEX of the obtained numbers.

An array $$$b$$$ is a subarray of an array $$$a$$$, if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possible none or all) elements from the beginning and several (possibly none or all) elements from the end. In particular, an array is a subarray of itself.

Lesha understands that the problem is very interesting this time, but he doesn't know how to solve it. Help him and find the MEX of MEXes of all the subarrays!

Input:

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array.

The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array.

Output:

Print a single integer — the MEX of MEXes of all subarrays.

Sample Input:

3
1 3 2

Sample Output:

3

Sample Input:

5
1 4 3 1 2

Sample Output:

6

Informação

Codeforces

Provedor Codeforces

Código CF1436E

Tags

binary searchdata structurestwo pointers

Submetido 0

BOUA! 0

Taxa de BOUA's 0%

Datas 09/05/2023 10:08:03

Relacionados

Nada ainda