MBLAST - BLAST

There are given two strings, A and B. An expansion of some string X is a string created by adding or inserting any number (zero, one or more) of blanks anywhere in the string, or in the begining or the end of the string. Eg., if the string X is ‘abcbcd’, then the strings 'abcb-cd', '-a-bcbcd-' and 'abcb-cd-' are expansions of the string X (blanks are denoted by the character ‘-‘).

If A1 is an expansion of the string A, and B1 is and expansion of the string B, and if A1 and B1 are of the same length, then we define the distance of the strings A1 and B1 as the sum of the distances of the characters on the same positions in these strings. We define the distance of two characters as the absolute difference of their ASCII codes, except the distance of the blank and another character, which is given (and equal for all characters).

You are to write a program which finds the expansions A1 and B1 of strings A and B, that have the smallest difference.

Input

The first line of the input file consists of the string A, and the second line of string B. They are consisted only of lower case characters of the english alphabet (a-z), and the number of characters in any of the strings is less than or equal to 2000.

The third line consists of an integer K, 1 ≤ K ≤ 100, the distance of the blank and the other characters.

Output

The first only line of the input file should consist of the smallest distance as defined in the text of the task.

Sample

Input:
cmc
snmn
2

output:
10
Input:
koiv
ua
1

output:
5
input: 
mj
jao
4

output:
12

Được gửi lên bởi:psetter
Ngày:2009-03-20
Thời gian chạy:1s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:Tất cả ngoại trừ: ERL GOSU JS-RHINO NODEJS PERL6 PYPY RUST SED VB.NET
Nguồn bài:COI 02

hide comments
2021-05-27 18:01:42
Tham khảo: https://vnspoj.github.io/problems/MBLAST
2017-10-23 08:31:42
Ơ đệt tưởng chấm theo kiểu file chớ :'(
2017-10-04 09:50:19
Code AC: http://123link.top/MBLAST
2015-12-13 02:59:03
THAM KHẢO TẠI https://traitaodo.wordpress.com/2015/12/13/blast-mblast/
2014-07-30 12:58:24 ■■‡[ND] Bee Sociu■■‡
co ai lam quen khong . cho sdt di nak :))~~
2013-04-27 15:27:04 Bitagi97
QHD rùi :')
2011-01-08 08:26:24 @__@
hint:
search for "string alignment using dynamic programing" on google
2011-01-08 08:26:24 @__@
hint:
search for "string alignment using dynamic programing" on google
2010-02-12 15:23:31 Siêu Nhân Trong Suốt
". Nếu hai kí tự không là dấu cách thì khoảng cách giữa 2 kí tự này là trị tuyệt đối HIỆU 2 kí tự này theo mã ASCII" mới đúng chứ :|

Last edit: 2010-02-12 15:37:22
2009-08-24 16:57:24 loc_konoko
Bai QHD co ban. Ma bai nay dau cham theo kieu file^.^

Last edit: 2009-08-24 16:58:34
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.