시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
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+XHJcblx0XHVjNWI0XHViNWE0IFx1YmIzOFx1Yzc5MFx1YzVmNCBYXHVjNzU4IFx1ZDY1NVx1YzdhNVx1Yzc3NFx1Yjc4MCBcdWFkZjggXHViYjM4XHVjNzkwXHVjNWY0XHVjNzU4IFx1YzViNFx1YjVhNCBcdWM3MDRcdWNlNTggXHViNjEwXHViMjk0IFx1YWMwMFx1YzdhNSBc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