PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000205. Giải cứu thành phố (Saving the City)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Giải cứu thành phố (Saving the City)

Saving the City

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Bertown contains a straight row of buildings. A binary string ss describes mines: 1 means a mine is already present under that building and 0 means there is none.

A sapper may manually activate an existing mine for aa coins. The blast propagates to mines under adjacent buildings, so one activation removes a whole contiguous block of mines. Alternatively, the sapper may place a new mine at a 0 position for bb coins, possibly connecting two blocks of existing mines.

Operations may be performed in any order. Find the minimum total cost of detonating all original mines. If there are no mines initially, the cost is zero.

Input

  • The first line contains two positive integers aa and bb: the manual activation and mine placement costs.
  • The second line contains a binary string ss describing buildings from left to right. Let n=∣s∣n=|s|.

Output

Print one integer: the minimum number of coins needed to detonate every mine originally present.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20; 1≤a,b≤10001\le a,b\le1000; ss contains only 0 and 1.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le2000; 1≤a,b≤10001\le a,b\le1000; ss contains only 0 and 1.
  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; 1≤a,b≤10001\le a,b\le1000; ss contains only 0 and 1.

Examples

Input

5 1
01101110

Output

6

Explanation

Here a=5a=5, b=1b=1, and the city is 01101110. Mines form two blocks at positions 2–3 and 5–7, separated by a single zero at position 4. Activating both blocks separately costs 1010. Placing one mine at position 4 costs 11 and connects them, so one activation for 55 suffices. The minimum total is 66.