n = int(input()) s = list(input()) A = list(map(int, input().split())) for i in range(n): if s[i] == "R": continue else: A[i] *= -1 cumA = [0] * (n + 1) for i in range(n): cumA[i + 1] = A[i] + cumA[i] plus = 0 minus = 0 pre_plus = 0 pre_minus = 0 for i in range(1, n + 1): score_plus = cumA[i] - cumA[pre_plus] score_minus = cumA[i] - cumA[pre_minus] if score_plus < 0: pre_plus = i if score_minus > 0: pre_minus = i plus = max(plus, score_plus) minus = min(minus, score_minus) print(max(plus, -minus))