#K54812. Minimum Replacements to Palindrome
Minimum Replacements to Palindrome
Minimum Replacements to Palindrome
You are given a string s consisting of lowercase letters. Your task is to determine the minimum number of character replacement operations needed to transform s into a palindrome. In each replacement operation, you can replace any character with any other character.
A palindrome is a string that reads the same backward as forward. For example, "abba" and "racecar" are palindromes.
The key observation is that only the mismatches in character pairs (from the beginning and the corresponding character from the end) need to be fixed. Formally, if we denote the string as s with indices starting at 0, you need to count the number of indices i (where 0 ≤ i < n/2) for which s[i] ≠ s[n-i-1].
Formally, if the string is represented as \( s_0 s_1 \dots s_{n-1} \), then the answer is:
\[ \text{replacements} = \sum_{i=0}^{\lfloor\frac{n-1}{2}\rfloor} [s_i \neq s_{n-i-1}], \]where \([s_i \neq s_{n-i-1}]\) is 1 if \(s_i \neq s_{n-i-1}\), and 0 otherwise.
inputFormat
Input consists of a single line containing a non-empty string s of lowercase letters.
outputFormat
Output a single integer representing the minimum number of character replacements required to make the string a palindrome.
## samplea
0