Palindrome
시간 제한1초메모리 제한1024 MB
각 항목을 같은 길이의 0이 아닌 숫자 문자열로 바꿀 수 있을 때, 이어 붙인 결과가 회문이 되도록 바꿔야 하는 최소 항목 수를 구한다.
문제
Little Square found an array consisting of positive numbers formed of nonzero digits. He can replace any number from 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.
입력
The first line of standard input 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.
출력
The standard output will contain only one integer, representing the minimum number of elements of the array a that need to be replaced.
제한
- , 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.
힌트
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.
In the second example, Little Square can replace the third number with .