#include #include int cmp_ll_rev (const void *ap, const void *bp) { long long a = *(long long *)ap; long long b = *(long long *)bp; if (a < b) { return 1; } if (a > b) { return -1; } return 0; } int main () { int n = 0; int x = 0; int y = 0; long long p = 0LL; char c = '\0'; int res = 0; long long ans = 0LL; long long sum[400000][3] = {}; int cnt[2] = {}; res = scanf("%d", &n); res = scanf("%d", &x); res = scanf("%d", &y); for (int i = 0; i < n; i++) { res = scanf("%lld", &p); res = scanf("%c", &c); res = scanf("%c", &c); if (c == 'A') { sum[i%(x+y)][1] += p; } else { sum[i%(x+y)][2] += p; } } for (int i = 0; i < x+y; i++) { if (sum[i][1] < sum[i][2]) { sum[i][0] = sum[i][2]-sum[i][1]; } else { sum[i][0] = sum[i][1]-sum[i][2]; } } qsort(sum, x+y, sizeof(long long)*3, cmp_ll_rev); for (int i = 0; i < x+y; i++) { if (sum[i][1] < sum[i][2] && cnt[1] < y) { ans += sum[i][2]; cnt[1]++; } else if (sum[i][1] < sum[i][2]) { ans += sum[i][1]; } else if (cnt[0] < x) { ans += sum[i][1]; cnt[0]++; } else { ans += sum[i][2]; } } printf("%lld\n", ans); return 0; }