#P1091F. New Year and the Mallard Expedition

    ID: 2873 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>constructive algorithmsgreedy*2600

New Year and the Mallard Expedition

No submission language available for this problem.

Description

Bob is a duck. He wants to get to Alice's nest, so that those two can duck!

Duck is the ultimate animal! (Image courtesy of See Bang)

The journey can be represented as a straight line, consisting of nn segments. Bob is located to the left of the first segment, while Alice's nest is on the right of the last segment. Each segment has a length in meters, and also terrain type: grass, water or lava.

Bob has three movement types: swimming, walking and flying. He can switch between them or change his direction at any point in time (even when he is located at a non-integer coordinate), and doing so doesn't require any extra time. Bob can swim only on the water, walk only on the grass and fly over any terrain. Flying one meter takes 11 second, swimming one meter takes 33 seconds, and finally walking one meter takes 55 seconds.

Bob has a finite amount of energy, called stamina. Swimming and walking is relaxing for him, so he gains 11 stamina for every meter he walks or swims. On the other hand, flying is quite tiring, and he spends 11 stamina for every meter flown. Staying in place does not influence his stamina at all. Of course, his stamina can never become negative. Initially, his stamina is zero.

What is the shortest possible time in which he can reach Alice's nest?

The first line contains a single integer nn (1n1051 \leq n \leq 10^5) — the number of segments of terrain.

The second line contains nn integers l1,l2,,lnl_1, l_2, \dots, l_n (1li10121 \leq l_i \leq 10^{12}). The lil_i represents the length of the ii-th terrain segment in meters.

The third line contains a string ss consisting of nn characters "G", "W", "L", representing Grass, Water and Lava, respectively.

It is guaranteed that the first segment is not Lava.

Output a single integer tt — the minimum time Bob needs to reach Alice.

Input

The first line contains a single integer nn (1n1051 \leq n \leq 10^5) — the number of segments of terrain.

The second line contains nn integers l1,l2,,lnl_1, l_2, \dots, l_n (1li10121 \leq l_i \leq 10^{12}). The lil_i represents the length of the ii-th terrain segment in meters.

The third line contains a string ss consisting of nn characters "G", "W", "L", representing Grass, Water and Lava, respectively.

It is guaranteed that the first segment is not Lava.

Output

Output a single integer tt — the minimum time Bob needs to reach Alice.

Samples

Sample Input 1

1
10
G

Sample Output 1

30

Sample Input 2

2
10 10
WL

Sample Output 2

40

Sample Input 3

2
1 2
WL

Sample Output 3

8

Sample Input 4

3
10 10 10
GLW

Sample Output 4

80

Note

In the first sample, Bob first walks 55 meters in 2525 seconds. Then he flies the remaining 55 meters in 55 seconds.

In the second sample, Bob first swims 1010 meters in 3030 seconds. Then he flies over the patch of lava for 1010 seconds.

In the third sample, the water pond is much smaller. Bob first swims over the water pond, taking him 33 seconds. However, he cannot fly over the lava just yet, as he only has one stamina while he needs two. So he swims back for half a meter, and then half a meter forward, taking him 33 seconds in total. Now he has 22 stamina, so he can spend 22 seconds flying over the lava.

In the fourth sample, he walks for 5050 seconds, flies for 1010 seconds, swims for 1515 seconds, and finally flies for 55 seconds.