#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int w = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    w = (w << 3) + (w << 1) + ch - 48;
    ch = getchar();
  }
  return w * f;
}
int n, A, B, ans, cnta, cntb;
struct node {
  int cost, val;
};
inline int comp(node x, node y) { return x.cost < y.cost; }
node a[100010];
node b[100010];
int main() {
  n = read();
  A = read();
  B = read();
  int i, j, k, maxxa = -1, maxxb = -1;
  for (i = 1; i <= n; i++) {
    int x, y;
    x = read();
    y = read();
    char ch;
    cin >> ch;
    if (ch == 'C') {
      if (y <= A) {
        cnta++;
        maxxa = max(maxxa, x);
        a[cnta].cost = y;
        a[cnta].val = x;
      }
    }
    if (ch == 'D') {
      if (y <= B) {
        cntb++;
        maxxb = max(maxxb, x);
        b[cntb].cost = y;
        b[cntb].val = x;
      }
    }
  }
  if (maxxa == -1 || maxxb == -1)
    ans = -1;
  else
    ans = maxxa + maxxb;
  sort(a + 1, a + cnta + 1, comp);
  sort(b + 1, b + cntb + 1, comp);
  if (maxxa != -1)
    for (i = 1; i <= cnta; i++) {
      for (j = i + 1; j <= cnta; j++) {
        if (a[i].cost + a[j].cost <= A) {
          ans = max(ans, a[i].val + a[j].val);
        } else
          break;
      }
    }
  if (maxxb != -1)
    for (i = 1; i <= cntb; i++) {
      for (j = i + 1; j <= cntb; j++) {
        if (b[i].cost + b[j].cost <= B) {
          ans = max(ans, b[i].val + b[j].val);
        } else
          break;
      }
    }
  if (ans == -1)
    cout << 0 << endl;
  else
    cout << ans << endl;
  return 0;
}
