N = int(input()) S = input() A = list(map(int,input().split())) l = [A[i] if S[i] == 'R' else -A[i] for i in range(N)] Sum = [0] * (N+1) for i in range(N): Sum[i+1] = Sum[i] + A[i] M = max(Sum) m = min(Sum) print(abs(M-m))