#include <bits/stdc++.h>
using namespace std;
int n, lc = 0, ld = 0, tc, td;
struct pq {
  int cost, val;
  pq() {}
  pq(int a, int b) : cost(a), val(b) {}
} coi[101010], dia[101010];
bool cmp(pq A, pq B) {
  if (A.cost != B.cost) return A.cost > B.cost;
  return A.val > B.val;
}
int main() {
  ios::sync_with_stdio(false);
  int aa, bb, tc, td, mac = 0, mad = 0;
  cin >> n >> tc >> td;
  char ty;
  for (int i = 1; i <= n; i++) {
    cin >> aa >> bb >> ty;
    if (ty == 'C') {
      if (bb <= tc) mac = max(aa, mac), coi[++lc] = pq(bb, aa);
    } else if (bb <= td)
      mad = max(aa, mad), dia[++ld] = pq(bb, aa);
  }
  sort(coi + 1, coi + lc + 1, cmp);
  sort(dia + 1, dia + ld + 1, cmp);
  if (!mac) {
    if (!mad || ld == 1 || dia[ld].cost + dia[ld - 1].cost > td) {
      cout << "0" << endl;
      return 0;
    }
  }
  if (!mad) {
    if (!mac || lc == 1 || coi[lc].cost + coi[lc - 1].cost > tc) {
      cout << "0" << endl;
      return 0;
    }
  }
  int i = 1, pos = lc, ma = 0, ans = 0;
  if (mac && mad) ans = mac + mad;
  int ma1 = 0, ma2 = 0;
  if (lc >= 2) {
    while (pos >= i) {
      while (pos > i && coi[pos].cost + coi[i].cost <= tc) {
        ma = max(coi[pos].val, ma);
        pos--;
      }
      if (ma) ans = max(ans, ma + coi[i].val);
      i++;
    }
    if (lc - pos > 2) {
      for (i = pos + 1; i <= lc; i++)
        if (coi[i].val > ma2) {
          ma2 = coi[i].val;
          if (ma2 > ma1) swap(ma2, ma1);
        }
      ans = max(ans, ma2 + ma1);
    }
  }
  i = 1, pos = ld, ma = 0;
  if (ld >= 2) {
    while (pos >= i) {
      while (pos > i && dia[pos].cost + dia[i].cost <= td) {
        ma = max(dia[pos].val, ma);
        pos--;
      }
      if (ma) ans = max(ans, ma + dia[i].val);
      i++;
    }
    ma1 = ma2 = 0;
    if (ld - pos > 2) {
      for (i = pos + 1; i <= ld; i++)
        if (dia[i].val > ma2) {
          ma2 = dia[i].val;
          if (ma2 > ma1) swap(ma2, ma1);
        }
      ans = max(ans, ma2 + ma1);
    }
  }
  cout << ans << endl;
  return 0;
}
