cswork / OAOpen practice workspace

AmazonOA #217

Get Minimum Errors

Estimated HardJudge-ready

Topics (AI-labelled)Prefix & RangesGreedyStrings

Replace each ! independently with 0 or 1. Every pair of indices i<j that forms 01 contributes x, and every pair that forms 10 contributes y; this is not limited to adjacent characters. Minimize the full cost, then take it modulo 1000000007.

Input

The first line contains a non-empty string consisting only of 0, 1 and !; the second line contains x y. Length ≤100000, 0≤x,y≤100000.

Output

Output a single integer, the answer.

Example 1

Input:

101!1
2 3

Output:

9

Example 2

Input:

!1
1 1

Output:

0

Example 3

Input:

01!0
2 2

Output:

6

Example notes

The answers are 9, 0 and 6; in the second example, replacing to get 11 produces no errors.

Editorial

Loading solution…