#include <cstdio>
#include <cstring>
using namespace std;
#define DIST(X,Y) (int)(((X)-(Y))>=0?((X)-(Y)):((Y)-(X)))
inline int MIN (int a, int b, int c)
{
if (a <= b)
return c <= a ? c : a;
else
return c <= b ? c : b;
}
int dym[2010][2010];
int main ()
{
freopen("blast.in", "r", stdin);
freopen("blast.out", "w", stdout);
char s1[2010], s2[2010];
scanf("%s", s1);
scanf("%s", s2);
int l1 = strlen(s1), l2 = strlen(s2), K;
scanf("%d", &K);
for (int i=1; i<=l1 || i<=l2; i++)
dym[0][i] = dym[i][0] = K*i;
for (int i=1; i<=l1; i++)
for (int j=1; j<=l2; j++)
dym[i][j] = MIN(dym[i-1][j-1]+DIST(s1[i-1],s2[j-1]),
dym[i-1][j]+K, dym[i][j-1]+K);
printf("%d\n", dym[l1][l2]);
return 0;
}