cho.sh
Notes
Loading...

Text Message

Time limit

2s

Memory limit

128 MB

Problem

Given the mobile phone numeric keypad below, compute the minimum time needed to type an English message.

KeyCharacters
1space
2A B C
3D E F
4G H I
5J K L
6M N O
7P Q R S
8T U V
9W X Y Z

To enter one character, press its key until that character appears. For example, pressing key 2 once enters A, twice enters B, and three times enters C.

If two consecutive characters use the same key, you must wait w time units before pressing the key for the second character. For example, typing A followed by C requires a wait before pressing key 2 again. Consecutive spaces are the exception: they do not require waiting.

Each key press takes p time units. Find the minimum time required to type the given message.

Input

The first line contains p and w (1 ≤ p, w ≤ 1,000). Here, p is the time required for one key press, and w is the waiting time required when the same key must be used for consecutive characters.

The second line contains the message to type. Its length is less than 1000, and it has no leading or trailing spaces. The message consists only of uppercase English letters and spaces.

Output

Print one line containing the minimum time required to type the message.