n = int(input()) s = input() a = list(map(int, input().split())) x = [0] for i in range(n): if s[i] == "R": x.append(x[-1]+a[i]) else: x.append(x[-1]-a[i]) ans=0 ma=0 for i in range(1, n+1): ans = max(ans, ma-x[i]) ma = max(x[i], ma) print(ans)