Palindrome

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

Little Square found an array aa consisting of NN positive numbers formed of nonzero digits. He can replace any number from aa with another number consisting of as many digits, all nonzero.

After making all the changes he wants, Little Square will form a new number MM by writing the elements of the array aa in order, without spaces. What is the minimum numbers of elements of the array aa which need to be replaced by Little Square for the number MM obtained to be a palindrome.

입력

The first line of standard input will contain an integer NN, the size of the array aa. The second line will contain NN integers consisting only of nonzero digits representing the array aa.

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.

제한

  • 1N500,0001 ≤ N ≤ 500\\,000
  • 1a_i<10181 ≤ a\_i < 10^{18}, for every 1iN1 ≤ i ≤ N
  • 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 44, 121121, 1454114541 are palindromes, while numbers 2121, 433433, 12343121234312 are not palindromes.

힌트

In the first example, Little Square can replace the first number with 1387913879 and the third number with 448448. The number MM will become 13879984489978311387998448997831 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 13477431125541347743112554.