import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); char[] s = br.readLine().toCharArray(); String[] sa = br.readLine().split(" "); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } br.close(); long max = 0; long min = 0; long[] b = new long[n + 1]; for (int i = 0; i < n; i++) { if (s[i] == 'R') { b[i + 1] = b[i] + a[i]; } else { b[i + 1] = b[i] - a[i]; } max = Math.max(max, b[i + 1]); min = Math.min(min, b[i + 1]); } System.out.println(max - min); } }