Task
Little Square found an array consisting of positive numbers formed of nonzero digits. He can replace any number from a with another number consisting of as many digits, all nonzero.
After making all the changes he wants, Little Square will form a new number by writing the elements of the array in order, without spaces. What is the minimum numbers of elements of the array which need to be replaced by Little Square for the number obtained to be a palindrome?
Input data
The first line of the input file palindrome.in
will contain an integer , the size of the array . The second line will contain integers consisting only of nonzero digits representing the array .
Attention! The numbers read from the input file may be too big for the int
data type. It is recommended to use the long long
data type.
Output data
The output file palindrome.out
will contain only one integer, representing the minimum number of elements of the array that need to be replaced.
Constraints
- , for every
- A number is a palindrome if its first digit is equal to its last one, its second digit is equal is equal to the next to last digit and so on. Thus, numbers are palindromes, while numbers are not palindromes.
# | Points | Constraints |
---|---|---|
1 | 10 | , for every |
2 | 10 | |
3 | 15 | |
4 | 20 | |
5 | 10 | can become a palindrome by replacing at most numbers. |
6 | 35 | No additional constraints. |
Example 1
palindrome.in
6
13577 98 348 997 8 31
palindrome.out
2
Explanation
In the first example, Little Square can replace the first number with and the third number with . The number will become which is a palindrome. There is no solution with less than two replacements.
Example 2
palindrome.in
3
455 21 1347742112664
palindrome.out
1
Explanation
In the second example, Little Square can replace the third number with .