Ensure that you are logged in and have the required permissions to access the test.
You are given the cost of changing M pairs of lowercase characters x to y. You are also given a string S.
You can change a character in string S to another lowercase character by spending the cost you were given earlier. Determine the minimum cost that is required to make S a palindrome.
You can assume that it is always possible to make S a palindrome.
Notes
Input format
Output format
Print the minimum cost that is required to make S a palindrome.
Constraints
1≤|S|≤105
0≤M≤325
1≤Ci≤108 where Ci is the cost of changing the ith pair of characters
To convert the string "mat" into a palindrome we can convert 'm' to 't' thus incurring a cost 10 and getting the string "tat" which is a palindrome. You can check that this is the minimum possible cost.