#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
int t[MAX * 2];
int n;
void build() {
  for (int i = n - 1; i > 0; i--) t[i] = max(t[i << 1], t[i << 1 | 1]);
}
void update(int i, int val) {
  for (t[i += n] = val; i >>= 1;) t[i] = max(t[i << 1], t[i << 1 | 1]);
}
int query(int l, int r) {
  int ans = 0;
  for (l += n, r += n; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1) {
    if (l & 1) ans = max(ans, t[l]);
    if (!(r & 1)) ans = max(t[r], ans);
  }
  return ans;
}
int t2[MAX * 2];
int n2;
void build2() {
  for (int i = n2 - 1; i > 0; i--) t2[i] = max(t2[i << 1], t2[i << 1 | 1]);
}
void update2(int i, int val) {
  for (t2[i += n2] = val; i >>= 1;) t2[i] = max(t2[i << 1], t2[i << 1 | 1]);
}
int query2(int l, int r) {
  int ans = 0;
  for (l += n2, r += n2; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1) {
    if (l & 1) ans = max(ans, t2[l]);
    if (!(r & 1)) ans = max(t2[r], ans);
  }
  return ans;
}
struct grupo {
  int b, c;
  grupo() {}
  grupo(int pb, int pc) : b(pb), c(pc) {}
};
bool operator<(const grupo &x, const grupo &y) {
  if (x.c != y.c)
    return x.c < y.c;
  else
    return x.b > y.b;
}
int c, d;
vector<grupo> tc, td;
vector<int> vc, vd;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int nn, x, y, ans;
  char z;
  while (cin >> nn >> c >> d) {
    tc.clear();
    td.clear();
    for (int i = 0; i < nn; i++) {
      cin >> x >> y >> z;
      if (z == 'C')
        tc.push_back(grupo(x, y));
      else if (z == 'D')
        td.push_back(grupo(x, y));
    }
    ans = 0;
    sort(tc.begin(), tc.end());
    n = (int)tc.size();
    vc = vector<int>(n);
    for (int i = 0; i < n; i++) {
      t[n + i] = tc[i].b;
      vc[i] = tc[i].c;
    }
    build();
    for (int i = 0; i < n; i++) {
      int pos =
          (int)(upper_bound(vc.begin(), vc.end(), c - vc[i]) - vc.begin()) - 1;
      update(i, 0);
      if (pos >= 0 && pos < n && query(0, pos) > 0)
        ans = max(ans, tc[i].b + query(0, pos));
      update(i, tc[i].b);
    }
    sort(td.begin(), td.end());
    n2 = (int)td.size();
    vd = vector<int>(n2);
    for (int i = 0; i < n2; i++) {
      t2[n2 + i] = td[i].b;
      vd[i] = td[i].c;
    }
    build2();
    for (int i = 0; i < n2; i++) {
      int pos =
          (int)(upper_bound(vd.begin(), vd.end(), d - vd[i]) - vd.begin()) - 1;
      update2(i, 0);
      if (pos >= 0 && pos < n2 && query2(0, pos) > 0)
        ans = max(ans, td[i].b + query2(0, pos));
      update2(i, td[i].b);
    }
    int pos1 = (int)(upper_bound(vc.begin(), vc.end(), c) - vc.begin()) - 1;
    int pos2 = (int)(upper_bound(vd.begin(), vd.end(), d) - vd.begin()) - 1;
    if (pos1 >= 0 && pos1 < n) {
      if (pos2 >= 0 && pos2 < n2) {
        ans = max(ans, query(0, pos1) + query2(0, pos2));
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
