N = int(input()) S = input() lsa = list(map(int,input().split())) lsB = [] lsR = [] ll = [] for i in range(N): if S[i] == 'R': ll.append(lsa[i]) else: ll.append(-lsa[i]) lssum = [0] for i in range(N): lssum.append(lssum[-1]+ll[i]) print(max(lssum)-min(lssum))