from itertools import combinations N = int(input()) S = input() A = list(map(int, input().split())) Sum = [0] * (N+1) for i in range(N): Sum[i+1] = Sum[i] + (A[i] if S[i] == 'R' else -A[i]) Max = 0 for l, r in combinations(range(N+1), 2): Max = max(Max, abs(Sum[l] - Sum[r])) print(Max)