#include typedef struct { long long key; int id; } data; typedef struct { data obj[200001]; int size; } max_heap; void push(max_heap* h, data x) { int i = ++(h->size), j = i >> 1; data tmp; h->obj[i] = x; while (j > 0) { if (h->obj[i].key > h->obj[j].key) { tmp = h->obj[j]; h->obj[j] = h->obj[i]; h->obj[i] = tmp; i = j; j >>= 1; } else break; } } data pop(max_heap* h) { int i = 1, j = 2; data output = h->obj[1], tmp; h->obj[1] = h->obj[(h->size)--]; while (j <= h->size) { if (j < h->size && h->obj[j^1].key > h->obj[j].key) j ^= 1; if (h->obj[j].key > h->obj[i].key) { tmp = h->obj[j]; h->obj[j] = h->obj[i]; h->obj[i] = tmp; i = j; j <<= 1; } else break; } return output; } int main() { int i, N, X, Y, P[200001]; char c[200001]; scanf("%d %d %d", &N, &X, &Y); for (i = 1; i <= N; i++) scanf("%d %c", &(P[i]), &(c[i])); int j; long long ans = 0, tmp[2]; max_heap h; data d; h.size = 0; for (i = 1; i <= N && i <= X + Y; i++) { for (j = i, tmp[0] = 0, tmp[1] = 0; j <= N; j += X + Y) { if (c[j] == 'A') tmp[0] += P[j]; else tmp[1] += P[j]; } d.key = tmp[0] - tmp[1]; push(&h, d); ans += tmp[1]; } while (X > 0 && h.size > 0) { X--; d = pop(&h); ans += d.key; } printf("%lld\n", ans); fflush(stdout); return 0; }