N = int(input()) S = input() A = list(map(int, input().split())) res = 0 for i in range(N): s = 0 for j in range(i, N): s += A[j] if S[j] == 'R' else -A[j] res = max(res, abs(s)) print(res)