Under construction

Still being built. Things may change

Just a Joystick

Interview

Time limit1sMemory limit1024 MB

Summary
Given two equal-length uppercase strings, find the fewest up or down joystick moves to change one into the other, with wrap-around between A and Z.
Level

Easy3 of 10

Topics
String, Greedy
Solved
No attempts yet

Problem

You just got the high score when playing Battlezone Asteroids Pac-Centipede on an arcade machine. On the 'Game Over' screen, you can enter your initials, one letter at a time. This arcade machine is modern, so it allows many more initials than the three that original machines accepted. You select the letters with only a joystick. For each letter, you move the joystick up or down to cycle through the letters, wrapping between 'Z' and 'A' in both directions. You move it to the right to go to the next letter.

The initials of the previous high-score winner are still filled in. Entering your own initials takes some time, and you want to know exactly how long. Using the most efficient method, how many times do you need to move the joystick up or down to enter your own initials?

Moves to the right are not counted.

Input

The first line contains an integer nn (1≤n≤1051 \leq n \leq 10^5), the number of letters available to enter your initials.

The second line contains a string of length nn, the initials of the previous high-score winner.

The third line contains a string of length nn, the initials that you want to enter.

The strings consist only of English uppercase letters (A-Z).

Output

Output the minimum number of times you should move the joystick up or down to enter your own initials. Moves to the right are not included.

Examples2

  1. Example 1

    Input
    3
    RGK
    MPS
    
    Expected output
    22
    
  2. Example 2

    Input
    5
    ABIYZ
    YZIAB
    
    Expected output
    8