#include <bits/stdc++.h>
using namespace std;
int n, c, d;
char h;
int treeC[500000];
int treeD[500000];
int sz = 1;
int SecC[100001];
int SecD[100001];
pair<pair<int, int>, char> arr[100001];
int my_res[100001];
void UpdC(int ind, int x) {
  ind += sz;
  treeC[ind] = x;
  ind >>= 1;
  while (ind > 0) {
    treeC[ind] = max(treeC[ind * 2], treeC[ind * 2 + 1]);
    ind >>= 1;
  }
}
void UpdD(int ind, int x) {
  ind += sz;
  treeD[ind] = x;
  ind >>= 1;
  while (ind > 0) {
    treeD[ind] = max(treeD[ind * 2], treeD[ind * 2 + 1]);
    ind >>= 1;
  }
}
int MaxC(int L, int R) {
  L += sz;
  R += sz;
  int res = 0;
  while (L <= R) {
    if (L & 1) res = max(res, treeC[L++]);
    if (!(R & 1)) res = max(res, treeC[R--]);
    L >>= 1;
    R >>= 1;
  }
  return res;
}
int MaxD(int L, int R) {
  L += sz;
  R += sz;
  int res = 0;
  while (L <= R) {
    if (L & 1) res = max(res, treeD[L++]);
    if (!(R & 1)) res = max(res, treeD[R--]);
    L >>= 1;
    R >>= 1;
  }
  return res;
}
int main() {
  while (sz < 100000) sz <<= 1;
  cin >> n >> c >> d;
  for (int i = 0; i < n; i++) {
    cin >> arr[i].first.first >> arr[i].first.second >> arr[i].second;
    if (arr[i].second == 'C') {
      int g = min(treeC[sz + arr[i].first.second], arr[i].first.first);
      UpdC(arr[i].first.second,
           max(treeC[sz + arr[i].first.second], arr[i].first.first));
      SecC[arr[i].first.second] = max(SecC[arr[i].first.second], g);
    } else {
      int g = min(treeD[sz + arr[i].first.second], arr[i].first.first);
      UpdD(arr[i].first.second,
           max(treeD[sz + arr[i].first.second], arr[i].first.first));
      SecD[arr[i].first.second] = max(SecD[arr[i].first.second], g);
    }
  }
  for (int i = 0; i < n; i++) {
    int g = 0;
    if (arr[i].second == 'C') {
      if (c < arr[i].first.second) continue;
      c -= arr[i].first.second;
      if (treeC[sz + arr[i].first.second] == arr[i].first.first) {
        g = 1;
        UpdC(arr[i].first.second, SecC[arr[i].first.second]);
      }
      my_res[i] = max(MaxC(0, c), MaxD(0, d));
      if (g == 1) UpdC(arr[i].first.second, arr[i].first.first);
      c += arr[i].first.second;
    } else {
      if (d < arr[i].first.second) continue;
      d -= arr[i].first.second;
      if (treeD[sz + arr[i].first.second] == arr[i].first.first) {
        g = 1;
        UpdD(arr[i].first.second, SecD[arr[i].first.second]);
      }
      my_res[i] = max(MaxC(0, c), MaxD(0, d));
      if (g == 1) UpdD(arr[i].first.second, arr[i].first.first);
      d += arr[i].first.second;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (my_res[i] != 0) ans = max(ans, my_res[i] + arr[i].first.first);
  }
  cout << ans;
  return 0;
}
