#include <bits/stdc++.h>
using namespace std;
int n, c, d, b1, b2, ans;
vector<pair<int, int> > p, q;
priority_queue<pair<int, int> > qq;
void doit(vector<pair<int, int> > p, int c) {
  while (qq.size()) qq.pop();
  for (int i = (0); i < (p.size()); i++) qq.push(make_pair(p[i].second, i));
  int ptr = p.size() - 1;
  for (int i = (0); i < (p.size()); i++) {
    while (ptr >= 0 && p[i].first + p[ptr].first > c) ptr--;
    if (ptr <= i) break;
    while (qq.size() && qq.top().second > ptr) qq.pop();
    if (qq.size()) {
      int index = qq.top().second;
      int profit = qq.top().first;
      if (index != i)
        ans = max(p[i].second + profit, ans);
      else {
        pair<int, int> temp = qq.top();
        qq.pop();
        while (qq.size() && qq.top().second > ptr) qq.pop();
        if (qq.size()) ans = max(p[i].second + qq.top().first, ans);
        qq.push(temp);
      }
    }
  }
}
int main() {
  scanf("%d %d %d", &n, &c, &d);
  for (int i = (0); i < (n); i++) {
    int a, b;
    char buf[3];
    scanf("%d %d %s", &a, &b, buf);
    if (buf[0] == 'C')
      p.push_back(make_pair(b, a));
    else
      q.push_back(make_pair(b, a));
  }
  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  b1 = b2 = -1;
  for (int i = (0); i < (p.size()); i++)
    if (p[i].first <= c) b1 = max(b1, p[i].second);
  for (int i = (0); i < (q.size()); i++)
    if (q[i].first <= d) b2 = max(b2, q[i].second);
  if (b1 >= 0 && b2 >= 0) ans = b1 + b2;
  doit(p, c);
  doit(q, d);
  printf("%d\n", ans);
}
