281 传统题

[ABC206D] 整数回文合并 (KAIBUNsyo)

时间限制
2000ms
内存限制
256MiB
登顶 / 尝试
0/ 0
难度
3

[ABC206D] 整数回文合并 (KAIBUNsyo)

Problem Statement

You are given a sequence of NN positive integers: A=(A1,A2,…AN)A=(A_1,A_2, \dots A_N). You can do the operation below zero or more times. At least how many operations are needed to make AA a palindrome?

  • Choose a pair (x,y)(x,y) of positive integers, and replace every occurrence of xx in AA with yy.

Here, we say AA is a palindrome if and only if Ai=AN+1−iA_i=A_{N+1-i} holds for every ii (1≤i≤N1 \le i \le N).

Input

Input is given from Standard Input in the following format:

$N$
$A_1$ $A_2$ $\dots$ $A_N$

Output

Print the answer as an integer.

Example

8
1 5 3 2 5 2 3 1
2

Note

  • Constraints:

  • All values in input are integers.

  • 1≤N≤2×1051 \le N \le 2 \times 10^5

  • 1≤Ai≤2×1051 \le A_i \le 2 \times 10^5

  • Source: ABC206D