n = int(input()) s = input() a = list(map(int, input().split())) b = [0] * (n + 1) for i in range(n): if s[i] == 'R': b[i + 1] = b[i] + a[i] else: b[i + 1] = b[i] - a[i] ans = 0 m = 0 for i in range(n): m = min(m, b[i + 1]) ans = max(ans, b[i + 1] - m) m = 0 for i in range(n): m = max(m, b[i + 1]) ans = max(ans, m - b[i + 1]) print(ans)