cswork / OAOpen practice workspace

AmazonOA #38

Calculate Min Cost (Password Removal)

EasyJudge-ready

Topics (AI-labelled)HashingStrings

You are given password, reference, and the deletion costs of the 26 lowercase letters. Delete every character in password that appears in the character set of reference; each deleted character is charged its letter's cost. Find the minimum total cost.

Input

The first line is password, the second line is reference, and the third line gives cost[0..25] in order. Both strings consist of lowercase English letters and have length 1..100000; each cost is 1..100. This site carries the original function parameters in a three-line stdin/stdout format.

Output

Output the minimum cost of deleting all characters in password that match reference.

Example 1

Input:

kkkk
k
1 1 1 1 1 1 1 1 1 1 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output:

20

Example 2

Input:

abac
ab
2 7 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output:

11

Example 3

Input:

abaabab
aba
2 7 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output:

29

Example 4

Input:

xyzzy
ab
1 82 61 8 23 18 13 28 91 50 37 48 23 22 1 4 87 94 9 44 23 2 81 76 35 86

Output:

0

Example notes

reference only determines the set of characters to delete; every matching position in password is charged separately.

Editorial

Loading solution…