cswork / OA打开练习工作台

AmazonOA #253

Make All Elements Distinct (Amazon London)

估计简单可在线判题

考点(AI 标注)哈希计数

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.

输入格式

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 a single integer, the answer.

样例 1

输入:

4
1 2 3 2

输出:

2

样例 2

输入:

3
1 2 3

输出:

0

样例 3

输入:

3
5 5 5

输出:

2

样例说明

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.