cswork / OAOpen practice workspace

AmazonOA #113

Cleanup Dataset

Estimated MediumJudge-ready

Topics (AI-labelled)HashingGreedy

Each time, choose any two positions and delete them; the cost is x if the characters are equal and y otherwise. Given a string of even length, find the minimum total cost to delete everything.

Input

The first line contains the string dataset (even length 2..100000), and the second line contains x y (1..10000).

Output

Output a single integer answer.

Example 1

Input:

aaabca
3 2

Output:

7

Example 2

Input:

ouio
2 4

Output:

6

Example 3

Input:

aabb
2 7

Output:

4

Example notes

Example 1: the four a characters must form at least one pair among themselves, and the other two pairs are mixed, for a total of 3+2+2=7. Example 2: pair oo and ui, for a total of 2+4=6. Example 3: delete aa and bb separately, at a cost of 4.

Editorial

Loading solution…