시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 3 3 3 100.000%

문제

어떤 문자열 X의 확장이란 그 문자열의 어떤 위치 또는 가장 앞과 뒤에 공백을 임의의 개수(0, 1또는 그 이상)만큼 추가하는 것이다. 예를 들어, 문자열 X가 'abcbcd'일 때, 'abcb-cd', '-a-bcbcd-', 'abcd-cd-'는 문자열 X의 확장이 된다. (공백은 '-'로 표시)

A1을 문자열 A의 확장이라고 하고, B1을 문자열 B의 확장이라고 했을 때, A1과 B1의 길이가 같다면, 두 문자열의 거리를 정의할 수 있다. 두 문자열의 거리란, 같은 위치에서 문자의 거리의 합이다. 문자의 거리란, ASCII 코드 값의 차이를 말한다. 이 때, 공백과 다른 문자와의 차이는 입력으로 주어지는 K이다.

두 문자열 A와 B가 주어졌을 때, 가장 짧은 거리를 갖는 A1과 B1을 찾는 프로그램을 작성하시오.

입력

첫째 줄에는 문자열 A가 주어진다. 둘째 줄에는 문자열 B가 주어진다. 두 문자열은 알파벳 소문자로만 이루어져 있으며, 길이는 2000보다 작거나 같다. 셋째 줄에는 공백과 다른 문자와의 거리 K가 주어진다. (1 ≤ K ≤ 100)

출력

첫째 줄에 가장 짧은 거리를 출력한다.

예제 입력 1

cmc
snmn
2

예제 출력 1

10
W3sicHJvYmxlbV9pZCI6IjMyNjYiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWJiMzhcdWM3OTBcdWM1ZjRcdWM3NTggXHVkNjU1XHVjN2E1XHVhY2ZjIFx1YWM3MFx1YjlhYyIsImRlc2NyaXB0aW9uIjoiPHA+XHJcblx0XHVjNWI0XHViNWE0IFx1YmIzOFx1Yzc5MFx1YzVmNCBYXHVjNzU4IFx1ZDY1NVx1YzdhNVx1Yzc3NFx1Yjc4MCBcdWFkZjggXHViYjM4XHVjNzkwXHVjNWY0XHVjNzU4IFx1YzViNFx1YjVhNCBcdWM3MDRcdWNlNTggXHViNjEwXHViMjk0IFx1YWMwMFx1YzdhNSB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