#include <bits/stdc++.h>
using namespace std;
ifstream fin("Sisend.txt");
int n, c, d, a, b;
char s;
int vaata(vector<pair<int, int>> cc, int c, int &ma) {
  vector<int> il;
  int m = 0, n = cc.size();
  for (int(i) = (0); ((i)) < ((n)); ((i))++) {
    m = max(m, cc[i].second);
    il.emplace_back(m);
  }
  int in = 0, it = 0, vas = 0;
  while (in < n and cc[in].first <= c) {
    int p = c - cc[in].first;
    while (it < in - 1 and cc[it + 1].first <= p) it++;
    while ((it >= 0 and cc[it].first > p) or it == in) it--;
    if (it > -1) vas = max(vas, il[it] + cc[in].second);
    ma = max(ma, cc[in].second);
    in++;
  }
  return vas;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  cin >> n >> c >> d;
  vector<pair<int, int>> cc, dd;
  for (int(i) = (0); ((i)) < ((n)); ((i))++) {
    cin >> a >> b >> s;
    if (s == 'C') {
      cc.emplace_back(b, a);
    }
    if (s == 'D') {
      dd.emplace_back(b, a);
    }
  }
  sort(cc.begin(), cc.end());
  sort(dd.begin(), dd.end());
  int vas = 0, ma1 = 0, ma2 = 0;
  if (cc.size() and cc[0].first <= c) vas = vaata(cc, c, ma1);
  if (dd.size() and dd[0].first <= d) vas = max(vas, vaata(dd, d, ma2));
  if (ma1 and ma2) vas = max(vas, ma1 + ma2);
  cout << vas;
}
