from sys import stdin def main(): input = lambda: stdin.readline()[:-1] N = int(input()) S = input() A = list(map(int, input().split())) if S[0] == "R": r, b = A[0], 0 else: r, b = 0, A[0] max_current = max_global = A[0] for i, n in enumerate(A[1:], start=1): if S[i] == "R": r += n else: b += n max_current = max(abs(n), abs(r - b)) if abs(n) > abs(r - b): if S[i] == "R": r, b = n, 0 else: r, b = 0, n if max_current > max_global: max_global = max_current print(max_global) main()