N = int(input()) S = input().strip() A = list(map(int,input().split())) for i in range(N): if S[i]=="R": A[i] = -A[i] A = [0]+A B = [0]*(N+1) for i in range(1,N+1): B[i] = B[i-1]+A[i] bmax = max(B) bmin = min(B) print(bmax-bmin)