Minimum cost to make two words equal

We are given two words ss and tt made up of only lowercase letters, and we must make them equal. We can only perform two kind of operations, as many times as needed: Remove a letter, with cost 3, and duplicate a letter, with cost 2. What is the minimum possible cost?

For example, for s=s=aaba” and t=t=abb” the minimum cost is 7, which corresponds to duplicating the ‘b’ and removing the last ‘a’ of ss, and duplicating the ‘a’ of tt.

Input

Input consists of several cases with ss and tt, both with between 1 and 1000 letters.

Output

For every case, print the minimum cost to make the two words equal.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T10:23:18.416Z

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