AlgoLensArena
ContestlərProblemlərOtaqlar
Vizualizator
← Məsələlər

DAPC23-047.Just a Joystick

Medium · 1 s · 256 MB

  • icpc
  • dapc
  • 2023

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 seems to be a very modern arcade machine: whereas the original arcade machines only allowed entering three initials, this machine allows many more. However, to select the letters, you have access to just a joystick. For every letter, you need to move the joystick up or down to cycle between the letters (wrapping around between ‘Z’ and ‘A’, in both directions) and move it to the right to move to the next letter.

It appears that the initials of the previous high-score winner are still filled in. Entering your own initials is going to take some time, and you want to know exactly how long. How many times do you need to you move the joystick up or down to enter your own initials, if you do so in the most efficient way?

Giriş formatı

The input consists of:

• One line with an integer nnn (1≤n≤1051 \leq n \leq 10^51≤n≤105), the number of letters available to enter your initials.

• One line with a string of length nnn, the initials of the previous high-score winner.

• One line with a string of length nnn, the initials that you want to enter.

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

Çıxış formatı

Output the minimum number of times you should move the joystick up or down to enter your own initials. This does not include the number of times that you need to move the joystick to the right.

Qeyd

Source: Delft Algorithm Programming Contest 2023 · Author: Maarten Sijm · License: CC BY-SA 4.0 · Original: https://dapc.wisv.ch · Statement adapted for AlgoLens and shared under the same license.

Nümunələr

Giriş #1

3
RGK
MPS

Çıxış #1

22

Giriş #2

5
ABIYZ
YZIAB

Çıxış #2

8