#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
struct Node {
  int beauty;
  int cost;
  char type;
} f[maxn];
int cidx[maxn], didx[maxn], tempBeauty[maxn];
bool compCost(int x, int y) { return f[x].cost < f[y].cost; }
int binSearch(int* arr, int r, int costStat) {
  int l = 0, mid = 0;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (f[arr[mid]].cost <= costStat)
      l = mid + 1;
    else
      r = mid - 1;
  }
  return l;
}
void singleChoose(int border, int& sum, int cost, int* arr) {
  int pos = 0;
  sort(arr, arr + border, compCost);
  tempBeauty[0] = f[arr[0]].beauty;
  for (int i = 1; i < border; i++) {
    tempBeauty[i] = max(tempBeauty[i - 1], f[arr[i]].beauty);
  }
  for (int i = border - 1; i >= 1; i--) {
    cost -= f[arr[i]].cost;
    pos = binSearch(arr, i - 1, cost);
    if (pos != 0) sum = max(sum, f[arr[i]].beauty + tempBeauty[pos - 1]);
    cost += f[arr[i]].cost;
  }
}
int main() {
  int n, c, d;
  scanf("%d %d %d", &n, &c, &d);
  for (int i = 0; i < n; i++) {
    scanf("%d %d %c", &f[i].beauty, &f[i].cost, &f[i].type);
  }
  int b1 = -1, b2 = -1, sum = 0;
  for (int i = 0; i < n; i++) {
    if (f[i].type == 'C' && f[i].cost <= c) b1 = max(b1, f[i].beauty);
    if (f[i].type == 'D' && f[i].cost <= d) b2 = max(b2, f[i].beauty);
  }
  if (b1 != -1 && b2 != -1) {
    sum = b1 + b2;
  }
  int cnt = 0, cnt2 = 0;
  for (int i = 0; i < n; i++) {
    if (f[i].type == 'C') {
      cidx[cnt] = i;
      cnt++;
    } else {
      didx[cnt2] = i;
      cnt2++;
    }
  }
  singleChoose(cnt, sum, c, cidx);
  singleChoose(cnt2, sum, d, didx);
  printf("%d\n", sum);
  return 0;
}
