We are given two words and 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
“aaba” and
“abb” the minimum cost is 7, which corresponds to
duplicating the ‘b’ and removing the last ‘a’
of
,
and duplicating the ‘a’ of
.
Input consists of several cases with and , both with between 1 and 1000 letters.
For every case, print the minimum cost to make the two words equal.
Input
a a a b a aa aaba abb xxxxzz zxxxx g ggggggg
Output
0 6 2 7 9 12