You are given the cost of changing
You can change a character in string
You can assume that it is always possible to make S a palindrome.
Notes
- Each pair of characters is there at most 1 time in the input.
- A string
is called a palindrome if it reads the same if it is read backwards. For example, 'radar', 'madam', 'racecar' are palindromes whereas 'pizza' is not.
Input format
- The first line contains string
. - The next line contains integer
. - The next
lines each contain a pair of lowercase characters , , and cost . You can change character to character or vise versa spending cost .
Output format
Print the minimum cost that is required to make
Constraints
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.
Please login to use the editor
You need to be logged in to access the code editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor