atcoder#ABC206D. [ABC206D] KAIBUNsyo
[ABC206D] KAIBUNsyo
Score : points
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 ().
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer as an integer.
8
1 5 3 2 5 2 3 1
2
- Initially, we have .
- After replacing every occurrence of in with , we have .
- After replacing every occurrence of in with , we have .
In this way, we can make a palindrome in two operations, which is the minimum needed.
7
1 2 3 4 1 2 3
1
1
200000
0
may already be a palindrome in the beginning.