import java.io.*; import java.util.*; public class B_TwoColorSequence { private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); private static StringTokenizer st; private static int readInt() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return Integer.parseInt(st.nextToken()); } public static void main(String[] args) throws IOException { int N = readInt(); String paint = br.readLine(); int[] a = new int[N]; for (int i = 0; i < N; i++) a[i] = readInt() * (paint.charAt(i) == 'R' ? -1 : 1); long answer = 0; long maxPos = Math.max(0, a[0]); long minNeg = Math.min(0, a[0]); for (int i = 1; i < N; i++) { maxPos = Math.max(maxPos + a[i], 0); answer = Math.max(answer, maxPos); minNeg = Math.min(minNeg + a[i], 0); answer = Math.max(answer, -minNeg); } System.out.println(answer); } }