N = int(input()) S = str(input()) A = list(map(int,input().split())) A0 = []; A1= [] for i in range(N): if S[i] == "R": val0 = A[i] val1 = -A[i] else: val0 = -A[i] val1 = A[i] A0.append(val0) A1.append(val1) #print(A0,A1) ans0 = 0 temp0 = 0 store0 = 0 for i in range(N): if A0[i] > 0: #temp0 += A0[i] store0 += A0[i] else: #temp0 = 0 store0 += A0[i] if store0 < 0: store0 = 0 #print(temp0,store0,A0[i]) ans0 = max(ans0,store0) #print(ans0) ans1 = 0 temp1 = 0 store1 = 0 for i in range(N): if A1[i] > 0: #temp1 += A1[i] store1 += A1[i] else: #temp1 = 0 store1 += A1[i] if store1 < 0: store1 = 0 #print(temp1,store1,A[i]) ans1 = max(ans1,store1) #print(ans1) print(max(ans0,ans1))