#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
struct Node {
  int beauty, cost;
  bool operator<(const Node& rhs) const { return beauty > rhs.beauty; }
} nodec[maxn], noded[maxn];
int main(void) {
  char ch;
  int i, j, n, C, D, nc = 0, nd = 0, t1, t2, ans = 0, indexc = 0, indexd = 0;
  cin >> n >> C >> D;
  for (int i = 0; i < n; i++) {
    cin >> t1 >> t2 >> ch;
    if (ch == 'C')
      nodec[nc].beauty = t1, nodec[nc++].cost = t2;
    else if (ch == 'D')
      noded[nd].beauty = t1, noded[nd++].cost = t2;
  }
  sort(nodec, nodec + nc), sort(noded, noded + nd);
  for (i = 0; i < nc; i++)
    if (nodec[i].cost <= C) {
      indexc = i, ans += nodec[i].beauty;
      break;
    }
  for (j = 0; j < nd; j++)
    if (noded[j].cost <= D) {
      indexd = j, ans += noded[j].beauty;
      break;
    }
  if (i == nc || j == nd) ans = 0;
  for (i = indexc; i < nc; i++)
    for (j = i + 1; j < nc; j++)
      if (nodec[i].cost + nodec[j].cost <= C) {
        ans = max(ans, nodec[i].beauty + nodec[j].beauty);
        break;
      }
  for (i = indexd; i < nd; i++)
    for (j = i + 1; j < nd; j++)
      if (noded[i].cost + noded[j].cost <= D) {
        ans = max(ans, noded[i].beauty + noded[j].beauty);
        break;
      }
  cout << ans << endl;
  return 0;
}
