#include <bits/stdc++.h>
using namespace std;
int n, c, d, ans, oc, od, p, b, bs;
vector<pair<int, int> > C, D, mc, md;
int BS(bool cc, int r, int second) {
  int l = 0, mid;
  while (l <= r) {
    mid = (l + r) / 2;
    if (cc && C[mid].first > second)
      r = mid - 1;
    else if (!cc && D[mid].first > second)
      r = mid - 1;
    else
      l = mid + 1;
  }
  if (cc)
    return C[r].first > second ? -1 : r;
  else
    return D[r].first > second ? -1 : r;
}
int main() {
  char second;
  scanf("%d%d%d", &n, &c, &d);
  for (int i = 0; i < n; i++) {
    scanf("%d%d %c", &b, &p, &second);
    if ((p > c && second == 'C') || (p > d && second == 'D')) continue;
    if (second == 'C')
      C.push_back({p, b}), oc = max(oc, b);
    else
      D.push_back({p, b}), od = max(od, b);
  }
  if (od && oc) ans = od + oc;
  sort(C.begin(), C.end());
  sort(D.begin(), D.end());
  int m = 0;
  for (int i = 0; i < C.size(); i++) {
    m = max(m, C[i].second);
    mc.push_back({C[i].first, m});
  }
  m = 0;
  for (int i = 0; i < D.size(); i++) {
    m = max(m, D[i].second);
    md.push_back({D[i].first, m});
  }
  for (int i = C.size() - 1; i > 0; i--) {
    bs = BS(1, i - 1, c - C[i].first);
    if (bs != -1) ans = max(ans, C[i].second + mc[bs].second);
  }
  for (int i = D.size() - 1; i > 0; i--) {
    bs = BS(0, i - 1, d - D[i].first);
    if (bs != -1) ans = max(ans, D[i].second + md[bs].second);
  }
  printf("%d", ans);
  return 0;
}
