Find the minimum cost to turn a string into a palindrome by moving a cursor and changing characters near a chosen position.
You are given a lowercase string and a starting cursor position. In one move, you may move the cursor left or right by one position, and moving one step costs 1. You may also change a character at the current cursor position to any other lowercase letter, and changing a character costs the minimum number of circular alphabet steps between the original and new letter.
Your task is to make the whole string a palindrome with minimum total cost. You can choose the order in which positions are visited, but every necessary character change must be performed while the cursor is on that position or its mirrored counterpart, depending on your chosen strategy.
Return the minimum possible total cost.
The exact source problem uses a single test case.
Example 1
Input
abca 1
Output
2
Explanation
The string is already almost a palindrome; changing one of the middle characters can make it a palindrome with cost 1, and the cursor movement can be arranged with minimal additional cost in this small example. (Illustrative example.)
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.