#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 9;
struct num {
  int val, cost;
};
num ac[maxn];
num ad[maxn];
int costa[maxn];
int costb[maxn];
bool cmp(num a, num b) {
  if (a.cost != b.cost) {
    return a.cost < b.cost;
  }
  return a.val < b.val;
}
int main() {
  int a, b, c, d, e, f, g, h, n;
  ios::sync_with_stdio(0);
  cin >> n >> c >> d;
  string s;
  num tmp;
  a = b = 0;
  for (int i = 0; i < n; i++) {
    cin >> e >> f >> s;
    tmp.val = e;
    tmp.cost = f;
    if (s[0] == 'C') {
      ac[a++] = tmp;
    } else {
      ad[b++] = tmp;
    }
  }
  sort(ac, ac + a, cmp);
  sort(ad, ad + b, cmp);
  g = 0;
  e = 0;
  f = 0;
  for (int i = 0; i < a; i++) {
    if (ac[i].cost <= c) {
      e = max(e, ac[i].val);
    }
  }
  for (int i = 0; i < b; i++) {
    if (ad[i].cost <= d) {
      f = max(f, ad[i].val);
    }
  }
  if (e > 0 && f > 0) {
    g = max(g, e + f);
  }
  h = 0;
  for (e = 0, f = a - 1; e < f;) {
    if (ac[e].cost + ac[f].cost <= c) {
      h = max(h, ac[e].val);
      g = max(g, h + ac[f].val);
      e++;
      costa[e] = h;
    } else {
      if (h > 0) {
        g = max(g, h + ac[f].val);
      }
      f--;
    }
  }
  for (int i = 1; costa[i] > 0; i++) {
    g = max(g, costa[i] + ac[i].val);
  }
  h = 0;
  for (e = 0, f = b - 1; e < f;) {
    if (ad[e].cost + ad[f].cost <= d) {
      h = max(h, ad[e].val);
      g = max(g, h + ad[f].val);
      e++;
      costb[e] = h;
    } else {
      if (h > 0) {
        g = max(g, h + ad[f].val);
      }
      f--;
    }
  }
  for (int i = 1; costb[i] > 0; i++) {
    g = max(g, costb[i] + ad[i].val);
  }
  cout << g << endl;
  return 0;
}
