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 mi=0 for i in range(1, n+1): ans = max(ans, x[i]-mi) mi = min(x[i], mi) print(ans)