""" Rの総和 Bの総和 で、R,B 片方が正・もう片方が負の寄与 """ import sys from sys import stdin N = int(stdin.readline()) n = N S = stdin.readline()[:-1] a = list(map(int,stdin.readline().split())) nmin = 0 now = 0 ans = 0 for i in range(n): if S[i] == "R": now += a[i] else: now -= a[i] ans = max(ans , now - nmin) nmin = min(nmin,now) nmin = 0 now = 0 for i in range(n): if S[i] == "R": now -= a[i] else: now += a[i] ans = max(ans , now - nmin) nmin = min(nmin,now) print (ans)