← 返回 ramp 的题目列表Minimum Changes to Make a K-Periodic Palindromic Password
类型:online_judge
Problem: Minimum Changes to Make a K-Periodic Palindromic Password
Given a password string password of length n and an integer k.
In one operation, you may change any character in password to any lowercase English letter.
Return the minimum number of character changes needed so that the new password satisfies both conditions:
The new password is k-periodic: for every index i such that i + k < n, password[i] == password[i + k].
The period pattern of length k is a palindrome: for every 0 <= r < k, the character at offset r in the period equals the character at offset k - 1 - r.
Equivalently, for each index i, all characters whose index modulo k is either i % k or k - 1 - (i % k) must become the same character.
Input Format
n k
password
Output Format
Print one integer: the minimum number of changes.
Constraints
1 <= k <= n <= 2 * 10^5
password contains only lowercase English letters 'a' to 'z'
Example 1
8 4
abcaabda
Output:
2
Example
Input
8 4
abcaabda
Output
2