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

#DSU0000034. Biến dãy thành đối xứng (KAIBUNsyo)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Biến dãy thành đối xứng (KAIBUNsyo)

KAIBUNsyo

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array AA of nn positive integers. The array is palindromic if reading it from left to right gives the same sequence as reading it from right to left. Equivalently, Ai=An+1−iA_i=A_{n+1-i} must hold for every index ii.

In one operation, choose two distinct positive integers xx and yy, then replace every current occurrence of xx in the array with yy. All other values remain unchanged. This operation affects an entire value class, not a single chosen position. You may perform operations repeatedly on the resulting array.

Find the minimum number of operations required to make the array palindromic.

Input

The first line contains nn. The next line contains nn integers AiA_i.

Output

Print the minimum number of operations.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20; 1≤Ai≤2⋅1051\le A_i\le2\cdot10^5.
  • Subtask 2 (30 points): 1≤n≤42001\le n\le4200; 1≤Ai≤2⋅1051\le A_i\le2\cdot10^5.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le2\cdot10^5; 1≤Ai≤2⋅1051\le A_i\le2\cdot10^5.

Examples

Input

8
1 5 3 2 5 2 3 1

Output

2

Explanation

Mirrored pairs are (1,1), (5,3), (3,2), (2,5). Values 2, 3, and 5 must become equal. Merging three distinct values requires two operations.