import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { static List> graph; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int x = sc.nextInt(); int y = sc.nextInt(); Group[] groups = new Group[x + y]; for (int i = 0; i < x + y; i++) { groups[i] = new Group(); } for (int i = 0; i < n; i++) { int idx = i % (x + y); int count = sc.nextInt(); char color = sc.next().charAt(0); if (color == 'A') { groups[idx].a += count; } else { groups[idx].b += count; } } Arrays.sort(groups); long ans = 0; for (int i = 0; i < x + y; i++) { if (i < x) { ans += groups[i].a; } else { ans += groups[i].b; } } System.out.println(ans); } static class Group implements Comparable { long a; long b; public int compareTo(Group another) { return Long.compare(b - a, another.b - another.a); } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }