#P12396. 「FAOI-R9」平民上篮

    ID: 11807 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>模拟洛谷原创O2优化洛谷月赛

「FAOI-R9」平民上篮

Description

The basketball rules for the high school entrance examination in City B are as follows:

  • A full set of movements for examinees is defined as dribbling to the basket, a successful layup, and returning to the three point line, with these three actions performed consecutively in sequence.
  • The criteria for determining the success of a set of movements are as follows: examinees must remain under the basket for a continuous period of time, during which only successful or failed shots can occur.A set is considered successful if a shot is made during this period. Specially, if (at least) three consecutive shots fail, it is also deemed successful.
  • Dribbling to the basket and returning are respectively the displacement from the three point line to under the basket and its reverse displacement.
  • The candidate is initially on the three-point line and needs to complete at least four complete sets of actions and return to the three-point line (meaning that even if all four sets of actions have been completed, the exam cannot be ended if Qingfeng is not on the three-point line). The total time for all actions is calculated. The score will be full if the time is within 35 seconds, and it will be zero if the time is outside 45 seconds.

Qingfeng can perform the following actions in this execrise:

  • If he is on the three point line, he can use aa seconds and dribble the ball to the basket,whose operation symbol is G. After this action, he is under the basket.
  • If he is under the basket, he can use aa seconds and dribble the ball to the three point line,whose operation symbol is B. After this action, he is on the three point line.
  • If he is under the basket, he can use bb seconds and aim for the layup ,whose operation symbol is A. Then, the basketball will definitely be thrown in. Or he can use cc seconds and casully layup,whose operation symbol is W. Then, the basketball won't be thrown in.

(Exam Rules Diagram)

Now a sequence of Qingfeng's operation sequence is given and it is ensured to be legal. Please help Qingfeng plan the remaining operations so that he can complete the basketball exam in the shortest total time (including the operations that have already been performed).

Input Format

The first line of input contains three integers a,b,ca,b,c, which denotes the time each operation cost.

The second line contains a string SS, which denotes the operation sequence.

Output Format

The only line contains an integer representing the shortest total time.

8 5 3
GWBGAABGAAABG
118
1 1 1
GABGABGABGABG
14
8 5 1
GBGBGBGB
140
1 5 2
GABGABGW
29
1 11 10
GBGW
64
1 50 1
GBGW
22

Hint

Sample Description

For the first test case: After the given operation sequence, the subsequent operations to be performed are: ABGAB.

For the last full set of movements: Obviously, making a layup successfully in one attempt is better than trying three times.

For the second test case: The movements were completed, but Qingfeng ran back under the basket, the correct action is to return.

For the third test case: Qingfeng needs repeat GWWWB four times; obviously, three attempts are better than making a layup successfully in one attempt.

For the fourth test case:

For incomplete full movements, obviously, trying twice is better than making a layup successfully in one attempt.

For unperformed full movements, obviously, making a layup successfully in one attempt is better than trying three times.

For the fifth test case: Obviously, for incomplete and unperformed full movements, trying at least twice or three times is not better than making a layup successfully in one attempt.

For the sixth test case: For incomplete and unperformed full movements, trying twice or three times is better than making a layup successfully in one attempt.

Constraints

The score of each test case is equal.

For test case 11, it is guaranteed that the exam can be ended directly by performing the given sequence of operations.

For test case 252\sim 5, it is guaranteed that b=cb=c.

For test case 6106\sim 10, there are no additional constraints.

For all test cases, it is guaranteed that 1S1001\le |S|\le 100, $S_i\in\{\texttt{G},\texttt{B},\texttt{A},\texttt{W}\}$, 1a,b,c1071\le a,b,c \le 10^7, bcb\ge c, and SS is legal.