cswork / OAOpen practice workspace

AmazonOA #253

Make All Elements Distinct (Amazon London)

Estimated EasyJudge-ready

Topics (AI-labelled)Hashing

Each operation can only delete the current leftmost element, never one from the middle. Find the minimum number of operations so that all remaining elements are distinct; if they are already distinct, the answer is 0.

Input

The first line contains n; the second line contains the identifiers. The original text had no numeric bounds; this site uses 1≤n≤200000, 1≤identifier≤10^9.

Output

Output a single integer, the answer.

Example 1

Input:

4
1 2 3 2

Output:

2

Example 2

Input:

3
1 2 3

Output:

0

Example 3

Input:

3
5 5 5

Output:

2

Example notes

The answers are 2, 0 and 2. In the first example both 1 and the first 2 must be deleted; you cannot delete only the 2 in the middle.

Editorial

Loading solution…