PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000085. Chia thành các khối (Into Blocks, Easy Version)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chia thành các khối (Into Blocks, Easy Version)

Into Blocks (Easy Version)

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

An integer sequence is nice if every value appears in exactly one contiguous block. For example, [3,3,3,4,1,1][3,3,3,4,1,1] is nice, while [3,1,3][3,1,3] is not.

You may change values to make the array nice, with the restriction that all positions having the same original value must receive the same final value. A value appearing originally in multiple places cannot be changed into different values at those places.

The cost is the number of positions whose final value differs from the original. Find the smallest possible cost.

This version has no update operations; only the original array is considered.

Input

The first line contains nn. The next line contains the nn elements of the array.

Output

Print the minimum number of array elements that must change.

Subtasks

  • Subtask 1 (20 points): 1≤n≤301\le n\le 30, 1≤ai≤301\le a_i\le 30.
  • Subtask 2 (30 points): 1≤n≤30001\le n\le 3000, 1≤ai≤30001\le a_i\le 3000.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le 2\cdot10^5, 1≤ai≤2⋅1051\le a_i\le 2\cdot10^5.

Example

Input

5
3 7 3 7 3

Output

2

Explanation

Values 33 and 77 interleave and must end up in one block. Keep the three 33s and change both 77s to 33; the optimal cost is 22.