N = int(input()) S = list(input()) A = list(map(int, input().split())) for i in range(N): if S[i] == "R": A[i] = -A[i] ma, mi = 0, 0 ans = 0 for i in range(N): ma = max(0, ma + A[i]) mi = min(0, mi + A[i]) ans = max(ans, ma, -mi) print(ans)