Another problem of the edit distance

Given two words made up with lowercase letters, compute the minimum cost of making them equal. The allowed operations are erasing a letter, increasing a letter (not ‘z’), and decreasing a letter (not ‘a’). Removing costs 10. Increasing and decreasing costs 1.

For example, if the words are “hello” and “hi”, the minimum cost is 33. One possible way is to delete the ‘e’, one ‘l’ and the ‘o’ of the first word, and increase 3 times the ‘i’ of the second word to make it an ‘l’.

Input

Input consists of several cases. Every case has two nonempty words, each with between 1 and 1000 lowercase letters.

Output

For every case, print the minimum cost of making the words equal.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T11:51:53.369Z

© Jutge.org, 2006–2026.
https://jutge.org