#include <bits/stdc++.h>
using namespace std;
int N, M, c, d, bt[100100], p[100100], a[100100], b[100100], vmax[100100];
char t[100100];
int main() {
  cin >> N >> c >> d;
  int i, bC = 0, bD = 0;
  int tot = N;
  N = 0;
  for (i = 1; i <= tot; i++) {
    cin >> bt[i] >> p[i] >> t[i];
    if (t[i] == 'C' && p[i] <= c)
      a[++N] = i, bC = max(bC, bt[i]);
    else if (t[i] == 'D' && p[i] <= d)
      b[++M] = i, bD = max(bD, bt[i]);
  }
  int res = 0;
  if (N && M) res = max(res, bC + bD);
  sort(a + 1, a + N + 1, [](int x, int y) { return p[x] < p[y]; });
  sort(b + 1, b + M + 1, [](int x, int y) { return p[x] < p[y]; });
  int l = -1;
  for (i = 1; i <= N; i++) {
    vmax[i] = max(vmax[i - 1], bt[a[i]]);
    l++;
    while (l > 0 && p[a[l]] + p[a[i]] > c) l--;
    if (l) res = max(res, bt[a[i]] + vmax[l]);
  }
  l = -1;
  for (i = 1; i <= M; i++) {
    vmax[i] = max(vmax[i - 1], bt[b[i]]);
    l++;
    while (l > 0 && p[b[l]] + p[b[i]] > d) l--;
    if (l) res = max(res, bt[b[i]] + vmax[l]);
  }
  cout << res << "\n";
  return 0;
}
