Under construction

Still being built. Things may change

Anagrams

Interview

Time limit2sMemory limit512 MB

Summary
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.
Level

Medium6 of 10

Topics
Greedy, Sorting, String, Math
Solved
No attempts yet

Problem

Elly has two strings AA and BB of the same length. She wants to change some of the letters of AA so that AA becomes an anagram of BB.

Two strings XX and YY 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 AA. '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 6+6+23+20=556 + 6 + 23 + 20 = 55 operations. Making "ELLY" an anagram of "KRIS" is cheaper: changing it to "IRSK" costs only 29 operations.

You are given the strings AA and BB. Compute the minimum number of operations needed to turn AA into a string XX that is an anagram of BB.

Input

The first line holds the string AA and the second line holds the string BB. Both strings contain only uppercase letters of the English alphabet ('A' to 'Z').

Output

Print one integer, the minimum number of increments.

Constraints

  • 1≤∣A∣=∣B∣≤501 \le |A| = |B| \le 50 (∣S∣|S| is the length of the string SS)

Examples3

  1. Example 1

    Input
    ELLY
    KRIS
    
    Expected output
    29
    
  2. Example 2

    Input
    TOPCODER
    TCOINDIA
    
    Expected output
    57
    
  3. Example 3

    Input
    AWIODJGWAMBAUWNMQEROAIQWYRZSVEPTT
    BNSIAELDALCGAWOPIWEQTYCNAZEKJXVYU
    
    Expected output
    105