import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); char[] colors = sc.next().toCharArray(); long min = 0; long max = 0; long value = 0; long ans = 0; for (int i = 0; i < n; i++) { int x = sc.nextInt(); if (colors[i] == 'B') { x *= -1; } value += x; ans = Math.max(ans, value - min); ans = Math.max(ans, max - value); min = Math.min(min, value); max = Math.max(max, value); } System.out.println(ans); } }