There is an n×mn times mn×m square grid graph with each square containing a lowercase letter.Alice wants to transform the grid graph into an elegant one where each row and column forms a palindrome string.Alice can change a letter on the grid graph to the next or last letter in the lexicographical order by spending one energy. For instance, the next letter of 'e' is 'f', and the last letter of 'e' is 'd'.Specially, the last letter of 'a' is 'z', and the next letter of 'z' is 'a'.Alice wants to know the minimum energy required to transform the grid graph into an elegant one.
There is an n×mn times mn×m square grid graph with each square containing a lowercase letter. Alice wants to transform the grid graph into an elegant one where each row and column forms a palindrome string. Alice can change a letter on the grid graph to the next or last letter in the lexicographical order by spending one energy. For instance, the next letter of 'e' is 'f', and the last letter of 'e' is 'd'. Specially, the last letter of 'a' is 'z', and the next letter of 'z' is 'a'. Alice wants to know the minimum energy required to transform the grid graph into an elegant one.