102063: [AtCoder]ABC206 D - KAIBUNsyo

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $400$ points

Problem Statement

You are given a sequence of $N$ positive integers: $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 $A$ a palindrome?

  • Choose a pair $(x,y)$ of positive integers, and replace every occurrence of $x$ in $A$ with $y$.

Here, we say $A$ is a palindrome if and only if $A_i=A_{N+1-i}$ holds for every $i$ ($1 \le i \le N$).

Constraints

  • All values in input are integers.
  • $1 \le N \le 2 \times 10^5$
  • $1 \le A_i \le 2 \times 10^5$

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.


Sample Input 1

8
1 5 3 2 5 2 3 1

Sample Output 1

2
  • Initially, we have $A=(1,5,3,2,5,2,3,1)$.
  • After replacing every occurrence of $3$ in $A$ with $2$, we have $A=(1,5,2,2,5,2,2,1)$.
  • After replacing every occurrence of $2$ in $A$ with $5$, we have $A=(1,5,5,5,5,5,5,1)$.

In this way, we can make $A$ a palindrome in two operations, which is the minimum needed.


Sample Input 2

7
1 2 3 4 1 2 3

Sample Output 2

1

Sample Input 3

1
200000

Sample Output 3

0

$A$ may already be a palindrome in the beginning.

Input

题意翻译

给你一个长度为 $N$ 的正数序列:$A= \{A_1,A_2, \cdots , A_N \}$。你可以做下边的操作零或者更多次,至少多少次操作能让序列 $A$ 变成回文序列? - 选择一对正数 $(x,y)$ ,然后将序列中的每一个 $x$ 都换为 $y$ 。 注:我们说 $A$ 是一个回文序列,当且仅当对于序列中每个元素,都有 $A_i=A_{N+1-i}(1 \leq i \leq N)$

加入题单

上一题 下一题 算法标签: