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