Alice and Bob are playing a game. The game involves splitting up game pieces into two teams. There are *n* pieces, and the *i*-th piece has a strength *p*<sub class="lower-index">*i*</sub>.

The way to split up game pieces is split into several steps:
 1.  First, Alice will split the pieces into two different groups *A* and *B*. This can be seen as writing the assignment of teams of a piece in an *n* character string, where each character is *A* or *B*. 1.  Bob will then choose an arbitrary prefix or suffix of the string, and flip each character in that suffix (i.e. change *A* to *B* and *B* to *A*). He can do this step at most once. 1.  Alice will get all the pieces marked *A* and Bob will get all the pieces marked *B*. 
The strength of a player is then the sum of strengths of the pieces in the group.

Given Alice's initial split into two teams, help Bob determine an optimal strategy. Return the maximum strength he can achieve.
The first line contains integer *n* (1 ≤ *n* ≤ 5·10<sup class="upper-index">5</sup>) — the number of game pieces.

The second line contains *n* integers *p*<sub class="lower-index">*i*</sub> (1 ≤ *p*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>) — the strength of the *i*-th piece.

The third line contains *n* characters *A* or *B* — the assignment of teams after the first step (after Alice's step).
In the first sample Bob should flip the suffix of length one.

In the second sample Bob should flip the prefix or the suffix (here it is the same) of length 5.

In the third sample Bob should do nothing.
5
1 2 3 4 5
ABABA
11
5
1 2 3 4 5
AAAAA
15
1
1
B
1
10
1 9 7 6 2 4 7 8 1 3
ABBABAABBB
33
100
591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983 526 103 500 963 400 23 276 704 570 757 410 658 507 620 984 244 486 454 802 411 985 303 635 283 96 597 855 775 139 839 839 61 219 986 776 72 729 69 20 917
BBBAAABBBABAAABBBBAAABABBBBAAABAAABBABABAAABABABBABBABABAAAABAABABBBBBBBABBAAAABAABABABAABABABAABBAB
30928
3
1 1 1
BAA
3
3
2 1 2
BAB
4
2
1 1
BB
2
1
1
A
1
2
1 1
AB
2
n=int(input())
p=list(map(int,input().split()))
s=input()
maxi=0
temp=0
local=-1
for i in range(n):
    if s[i]=='A':
        temp+=p[i]
    else:
        temp-=p[i]
    if temp>maxi:
        local=i
        maxi=temp
ans=0

for i in range(local+1):
    if s[i]=='A':
        ans+=p[i]


for i in range(local+1,n):
    if s[i]=='B':
        ans+=p[i]

maxi=0
temp=0
local=-1
p=list(reversed(p))
s=s[::-1]
for i in range(n):
    if s[i]=='A':
        temp+=p[i]
    else:
        temp-=p[i]
    if temp>maxi:
        local=i
        maxi=temp
ans1=0
for i in range(local+1):
    if s[i]=='A':
        ans1+=p[i]
for i in range(local+1,n):
    if s[i]=='B':
        ans1+=p[i]

print(max(ans,ans1))
