[ABC206D] 整数回文合并 (KAIBUNsyo)
Problem Statement
You are given a sequence of positive integers: . You can do the operation below zero or more times. At least how many operations are needed to make a palindrome?
- Choose a pair of positive integers, and replace every occurrence of in with .
Here, we say is a palindrome if and only if holds for every ().
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.
-
-
-
Source: ABC206D