#include <bits/stdc++.h>
using namespace std;
int pr[100005], bt[100005], mbt[100005];
int process(vector<pair<int, int> > &b, int c) {
  sort(b.begin(), b.end());
  int n = b.size();
  for (int i = 0; i < n; i++) {
    pr[i] = b[i].first;
    bt[i] = b[i].second;
    if (i != 0)
      mbt[i] = max(bt[i], mbt[i - 1]);
    else
      mbt[i] = bt[i];
  }
  int ans = 0;
  for (int i = 1; i < n; i++) {
    int ind = upper_bound(pr, pr + i, c - pr[i]) - pr;
    ind--;
    if (ind < 0) continue;
    ans = max(ans, bt[i] + mbt[ind]);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(30);
  int n, c, d;
  cin >> n >> c >> d;
  int b, p;
  char ch;
  vector<pair<int, int> > b1, b2;
  int mxb1 = 0, mxb2 = 0;
  for (int i = 1; i <= n; i++) {
    cin >> b >> p >> ch;
    if (ch == 'C' && p <= c) {
      b1.push_back({p, b});
      mxb1 = max(mxb1, b);
    }
    if (ch == 'D' && p <= d) {
      b2.push_back({p, b});
      mxb2 = max(mxb2, b);
    }
  }
  if (b1.size() + b2.size() < 2) {
    cout << 0 << endl;
    exit(0);
  }
  int ans = 0;
  if (!b1.empty() && !b2.empty()) ans = mxb1 + mxb2;
  if (b1.size() > 1) ans = max(ans, process(b1, c));
  if (b2.size() > 1) ans = max(ans, process(b2, d));
  cout << ans << endl;
}
