import sys import pypyjit import itertools import heapq import math from collections import deque, defaultdict import bisect input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) pypyjit.set_param('max_unroll_recursion=-1') def index_lt(a, x): 'return largest index s.t. A[i] < x or -1 if it does not exist' return bisect.bisect_left(a, x) - 1 def index_le(a, x): 'return largest index s.t. A[i] <= x or -1 if it does not exist' return bisect.bisect_right(a, x) - 1 def index_gt(a, x): 'return smallest index s.t. A[i] > x or len(a) if it does not exist' return bisect.bisect_right(a, x) def index_ge(a, x): 'return smallest index s.t. A[i] >= x or len(a) if it does not exist' return bisect.bisect_left(a, x) class SegTree: def __init__(self, N, func, e): self.N = N self.func = func self.X = [e] * (N << 1) self.e = e def build(self, seq): for i in range(self.N): self.X[self.N + i] = seq[i] for i in range(self.N)[::-1]: self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1]) def add(self, i, x): i += self.N self.X[i] += x while i > 1: i >>= 1 self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1]) def update(self, i, x): i += self.N self.X[i] = x while i > 1: i >>= 1 self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1]) def query(self, L, R): L += self.N R += self.N vL = self.e vR = self.e while L < R: if L & 1: vL = self.func(vL, self.X[L]) L += 1 if R & 1: R -= 1 vR = self.func(self.X[R], vR) L >>= 1 R >>= 1 return self.func(vL, vR) N = int(input()) T = input()[:-1] A = list(map(int, input().split())) A = [A[i] if T[i] == 'R' else -A[i] for i in range(N)] S = [0] * N S[0] = A[0] for i in range(1, N): S[i] = S[i - 1] + A[i] INF = 1 << 30 stmin = SegTree(N, min, INF) stmax = SegTree(N, max, -INF) stmin.build(S) stmax.build(S) ans = -INF for i in range(N): ma = stmax.query(i, N) mi = stmin.query(i, N) s = S[i - 1] if i > 0 else 0 ans = max(ans, ma - s) ans = max(ans, -(mi - s)) print(ans)