Anagrams
InterviewTime limit2sMemory limit512 MB
Given two equal-length uppercase strings A and B, find the minimum total number of cyclic letter increments applied to positions of A so the result is an anagram of B.
Problem
Elly has two strings and of the same length. She wants to change some of the letters of so that becomes an anagram of .
Two strings and are anagrams of each other when the letters of one of them can be rearranged into the other.
The only operation Elly can make is to cyclically increment one or more times some (possibly none or all) of the characters in . 'A' becomes 'B', 'K' becomes 'L', and 'Z' becomes 'A' again.
For example, turning "ELLY" into "KRIS" position by position costs 6 operations from 'E' to 'K', 6 more from 'L' to 'R', 23 from the second 'L' to 'I' (the 15th operation goes from 'Z' to 'A'), and 20 from 'Y' to 'S' (the 2nd operation goes from 'Z' to 'A'). The total is operations. Making "ELLY" an anagram of "KRIS" is cheaper: changing it to "IRSK" costs only 29 operations.
You are given the strings and . Compute the minimum number of operations needed to turn into a string that is an anagram of .
Input
The first line holds the string and the second line holds the string . Both strings contain only uppercase letters of the English alphabet ('A' to 'Z').
Output
Print one integer, the minimum number of increments.
Constraints
- ( is the length of the string )