#include <bits/stdc++.h>
using namespace std;
int n, c, d;
int dds, ccs;
pair<int, int> cc[100000], dd[100000];
int main() {
  scanf("%d %d %d\n", &n, &c, &d);
  int be, co;
  char ch;
  for (int i = 0; i < n; i++) {
    scanf("%d %d %c\n", &be, &co, &ch);
    if (ch == 'C') {
      cc[ccs++] = make_pair(co, be);
    } else {
      dd[dds++] = make_pair(co, be);
    }
  }
  sort(cc, cc + ccs);
  sort(dd, dd + dds);
  int ans = 0;
  if (ccs >= 1 && cc[0].first <= c && dds >= 1 && dd[0].first <= d) {
    for (int i = 0; i < ccs; i++) {
      if (cc[i].first <= c) {
        ans = max(ans, cc[i].second);
      }
    }
    int tmp = 0;
    for (int i = 0; i < dds; i++)
      if (dd[i].first <= d) tmp = max(tmp, dd[i].second);
    ans += tmp;
  }
  if (ccs >= 2) {
    multiset<int> ms;
    for (int i = 1; i < ccs; i++) ms.insert(cc[i].second);
    int l = 0, r = ccs - 1;
    while (l < r) {
      if (cc[l].first + cc[r].first <= c) {
        ans = max(ans, cc[l].second + *ms.rbegin());
        l++;
        ms.erase(ms.find(cc[l].second));
      } else {
        ms.erase(ms.find(cc[r].second));
        r--;
      }
    }
  }
  if (dds >= 2) {
    multiset<int> ms;
    for (int i = 1; i < dds; i++) ms.insert(dd[i].second);
    int l = 0, r = dds - 1;
    while (l < r) {
      if (dd[l].first + dd[r].first <= d) {
        ans = max(ans, dd[l].second + *ms.rbegin());
        l++;
        ms.erase(ms.find(dd[l].second));
      } else {
        ms.erase(ms.find(dd[r].second));
        r--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
