uses math;
const maxn = 2000;
var a,b:ansistring;
k,i,j:longint;
f: array[0..maxn,0..maxn] of longint;
begin
readln(a);
readln(b);
while a[length(a)]=' ' do delete(a,length(a),1);
while b[length(b)]=' ' do delete(b,length(b),1);
readln(k);
for i:=0 to length(a) do
f[i,0]:=i*k;
for i:=1 to length(b) do
f[0,i]:=i*k;
for i:=1 to length(a) do
begin
for j:=1 to length(b) do
begin
f[i,j]:=min(min(f[i-1,j]+k,f[i,j-1]+k),f[i-1,j-1]+abs(ord(a[i])-ord(b[j])));
end;
end;
writeln(f[length(a),length(b)]);
end.
dXNlcyBtYXRoOwpjb25zdCBtYXhuID0gMjAwMDsKdmFyIGEsYjphbnNpc3RyaW5nOwogICAgayxpLGo6bG9uZ2ludDsKICAgIGY6IGFycmF5WzAuLm1heG4sMC4ubWF4bl0gb2YgbG9uZ2ludDsKYmVnaW4KICByZWFkbG4oYSk7CiAgcmVhZGxuKGIpOwogIHdoaWxlIGFbbGVuZ3RoKGEpXT0nICcgZG8gZGVsZXRlKGEsbGVuZ3RoKGEpLDEpOwogIHdoaWxlIGJbbGVuZ3RoKGIpXT0nICcgZG8gZGVsZXRlKGIsbGVuZ3RoKGIpLDEpOwogIHJlYWRsbihrKTsKICBmb3IgaTo9MCB0byBsZW5ndGgoYSkgZG8KICBmW2ksMF06PWkqazsKICBmb3IgaTo9MSB0byBsZW5ndGgoYikgZG8KICBmWzAsaV06PWkqazsKICBmb3IgaTo9MSB0byBsZW5ndGgoYSkgZG8KICBiZWdpbgogICAgZm9yIGo6PTEgdG8gbGVuZ3RoKGIpIGRvCiAgICBiZWdpbgogICAgICBmW2ksal06PW1pbihtaW4oZltpLTEsal0rayxmW2ksai0xXStrKSxmW2ktMSxqLTFdK2FicyhvcmQoYVtpXSktb3JkKGJbal0pKSk7CiAgICBlbmQ7CiAgZW5kOwogIHdyaXRlbG4oZltsZW5ndGgoYSksbGVuZ3RoKGIpXSk7CmVuZC4=