Hermoine's Magic

0

0 votes
Medium
Problem

Hermione has a knows a magical spell to teleport words.

She can teleport words in two ways, each teleport takes a minute to work a and b. Help her to convert her move a to b

In a one minute, she can teleport any letter by spell a by one, that is, in a minute, she can convert letter A to B, B to C, C to D and so on. She can also teleport Z to A.

She comes to know that she can take help from Ron Weasley and can teleport any letter using spell b by 13 that is she can teleport any single letter by 13 like A to N, B into letter O, M into letter Z, O to B and so on.

Harry Potter challenges her to teleport by taking minimum time.

Help Hermione to accept the challenge and teleport faster....!!!

Constraints:

  • 1|a|=|b|105
  • a and b consists of uppercase English letters only

Input format:

  • First line contains an integer n, the length of strings a and b
  • Second line contains string a of length n
  • Third line contains string b of length n 

Output format:

  • Output single line containing the minimum time required
Sample Input
4
ABCT
PBDI
Sample Output
7
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

Hermione can convert teleport with help of Ron from a to b in 7 minutes as follows:

1. A>N (1st letter)

2. N>O (1st letter)

3. O>P (1st letter)

4. C>D (3rd letter)

5. T>G (4th letter)

6. G>H (4th letter)

7. H>I (4th letter)

Editor Image

?