n = int(input()) S = input() A = list(map(int, input().split())) for i in range(n): if S[i] == "R": A[i] *= -1 tot = 0 max_ = 0 min_ = 0 ans = 0 for a in A: tot += a min_ = min(min_, tot) max_ = max(max_, tot) ans = max(ans, max_ - tot, tot - min_) print(ans)