N = int(input()) S = input() A = list(map(int, input().split())) res = 0 maxs, mins = 0, 0 for i in range(N): v = A[i] if S[i] == 'R' else -A[i] maxs = max(maxs + v, v) mins = min(mins + v, v) res = max(res, abs(maxs), abs(mins)) print(res)