n = int(input()) S = str(input()) A = list(map(int, input().split())) for i, a in enumerate(A): if S[i] == 'R': A[i] = a else: A[i] = -a INF = 10**18 dp1 = [-INF]*(n+1) for i in range(n): dp1[i+1] = max(A[i], dp1[i]+A[i]) ans1 = max(0, max(dp1[1:])) dp2 = [INF]*(n+1) for i in range(n): dp2[i+1] = min(A[i], dp2[i]+A[i]) ans2 = min(0, min(dp2[1:])) print(max(abs(ans1), abs(ans2)))