The one of the edition distance (I)

Some problems are so classic that barely need a statement. For this one,
please compute the minimum cost to insert letters into two words w₁ and
w₂ to make them identical. Both words are made up of only letters chosen
among the n smallest lowercase letters (for instance, for n = 4, the
alphabet is {a, b, c, d}). For every letter (call it x), inserting an x
in any place in any word has cost I_(x).

Input

Input consists of several cases. Each case begins with 2 ≤ n ≤ 26,
followed by n strictly positive natural numbers
$I_{\mbox{\texttt{a}}}, I_{\mbox{\texttt{b}}}, I_{\mbox{\texttt{c}}}, \ldots$.
Follow two words w₁ and w₂ made up of between 1 and 1000 lowercase
letters chosen among the n smallest letters. Assume 1 ≤ I_(x) ≤ 1000 for
every letter x.

Output

For every case, print the minimum cost to make w₁ and w₂ identical.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:27:26.338Z

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