#P1279. 字串距离

字串距离

Description

Given a string XX, we call any new string formed by inserting any number of spaces at the beginning, end, or between characters of XX an extended string of XX. For example, if XX is abcbcd\verb!abcbcd!, then abcb␣cd\verb!abcb␣cd!, ␣a␣bcbcd␣\verb!␣a␣bcbcd␣!, and abcb␣cd␣\verb!abcb␣cd␣! are all extended strings of XX, where \verb!␣! denotes the space character.

If A1A_1 is an extended string of AA, B1B_1 is an extended string of BB, and A1A_1 and B1B_1 have the same length, then we define the distance between A1A_1 and B1B_1 as the sum of the distances at corresponding positions. The distance between two non-space characters is defined as the absolute difference of their ASCII codes. The distance between a space character and any other character is a given constant KK, and the distance between a space and a space is 00. Among all extended strings of AA and BB, there must exist two extended strings A1A_1 and B1B_1 of equal length such that the distance between A1A_1 and B1B_1 is minimized. We define this minimal value as the distance between strings AA and BB.

Please write a program to compute the distance between strings AA and BB.

Input Format

The first line contains string AA, and the second line contains string BB. Both AA and BB consist of lowercase letters, and each has length at most 20002000. The third line contains an integer K(1K100)K(1\leq K\leq 100), which is the distance between a space and any other character.

Output Format

Output a single line containing an integer, which is the distance between AA and BB.

cmc
snmn
2

10

Hint

Translated by ChatGPT 5