{"trustable":true,"sections":[{"title":"","value":{"format":"MD","content":"\u003cp\u003ePalindrome is a string that reads the same backward as forward, e.g., madam.\u003c/p\u003e\n\u003cp\u003eYou are given a string whose length is even, and each character of the string is either \u0027a\u0027, \u0027b\u0027 or \u0027/\u0027 Your task is to replace each occurrence of \u0027/\u0027 in string with either \u0027a\u0027 or \u0027b\u0027 such that the string becomes a palindrome.\u003c/p\u003e\n\u003cp\u003eYou are also given two integers, aCost and bCost. Replacing \u0027/\u0027 with \u0027a\u0027 costs aCost, and replacing \u0027/\u0027 with \u0027b\u0027 costs bCost.\u003c/p\u003e\n\u003cp\u003eReturn the minimum cost of replacing \u0027/\u0027 by \u0027a\u0027 and \u0027b\u0027 such that the string turns into a palindrome. If it is impossible to obtain a palindrome, return -1.\u003c/p\u003e\n\u003cp\u003eConstraints\u003c/p\u003e\n\u003cp\u003e string will contain between 1 and 10000 characters, inclusive. The length of string will be even. Each character of the string will be either \u0027a\u0027 or \u0027b\u0027 or \u0027/\u0027. aCost will be between 1 and 100, inclusive. bCost will be between 1 and 100, inclusive.\u003c/p\u003e\n\u003cp\u003eInput Format\u003c/p\u003e\n\u003cp\u003eFirst line of input will contain the number of test cases. For each test case, there will be of three lines, the first line is the string whose palindrome is to be constructed, the second is the aCost and the third is the bCost\u003c/p\u003e\n\u003cp\u003eExamples\u003c/p\u003e\n\u003cp\u003e1\u003c/p\u003e\n\u003cp\u003eaba/bab/\u003c/p\u003e\n\u003cp\u003e4\u003c/p\u003e\n\u003cp\u003e6\u003c/p\u003e\n\u003cp\u003eReturns: 10\u003c/p\u003e\n\u003cp\u003eThe only way to produce a palindrome is to replace 4th character of string with \u0027b\u0027 and 8th character with \u0027a\u0027. The first replacement costs 4, the second costs 6, so the total cost is 4+6\u003d10.\u003c/p\u003e\n\u003cp\u003eaaaabbbb\u003c/p\u003e\n\u003cp\u003e12\u003c/p\u003e\n\u003cp\u003e34\u003c/p\u003e\n\u003cp\u003eReturns: -1\u003c/p\u003e\n\u003cp\u003eThere is no \u0027/\u0027 character, and string is not a palindrome. We have no way to change it into a palindrome.\u003cbr /\u003e\u003cbr /\u003e\n\u003cb\u003e Sample Input: \u003c/b\u003e\u003c/p\u003e\n\u003cp\u003e1\u003cbr /\u003e baba//aaa/ab//\u003cbr /\u003e 72 \u003cbr /\u003e23\u003c/p\u003e\n\u003cp\u003e\u003cb\u003eSample Output:\u003c/b\u003e\u003c/p\u003e\n\u003cp\u003e213\u003c/p\u003e\n"}}]}