#include <bits/stdc++.h>
using namespace std;
int n, c, d, d1, d2, res;
pair<int, int> a[3][111111];
int M[111111][30];
int get(int u, int v) {
  if (u > v) return 0;
  int k = log2(v - u + 1);
  return max(M[u][k], M[v - (1 << k) + 1][k]);
}
void xuli1() {
  sort(a[1] + 1, a[1] + d1 + 1);
  ;
  for (int i = 1; i <= d1; i++) M[i][0] = a[1][i].second;
  for (int k = 1; (1 << k) <= d1; k++)
    for (int i = 1; i + (1 << k) - 1 <= d1; i++)
      M[i][k] = max(M[i][k - 1], M[i + (1 << (k - 1))][k - 1]);
  for (int i = 1; i <= d1; i++) {
    int diff = c - a[1][i].first;
    if (diff <= 0) continue;
    int pos2 =
        upper_bound(a[1] + 1, a[1] + d1 + 1, make_pair(diff, 1000000007)) -
        a[1];
    if (pos2 < i) continue;
    int tt = max(get(1, i - 1), get(i + 1, pos2 - 1));
    if (tt == 0) continue;
    int ans = a[1][i].second + tt;
    if (ans > res) res = ans;
  }
}
void xuli2() {
  sort(a[2] + 1, a[2] + d2 + 1);
  ;
  for (int i = 1; i <= d2; i++) M[i][0] = a[2][i].second;
  for (int k = 1; (1 << k) <= d2; k++)
    for (int i = 1; i + (1 << k) - 1 <= d2; i++)
      M[i][k] = max(M[i][k - 1], M[i + (1 << (k - 1))][k - 1]);
  for (int i = 1; i <= d2; i++) {
    int diff = d - a[2][i].first;
    if (diff <= 0) continue;
    int pos2 =
        upper_bound(a[2] + 1, a[2] + d2 + 1, make_pair(diff, 1000000007)) -
        a[2];
    if (pos2 < i) continue;
    int tt = max(get(1, i - 1), get(i + 1, pos2 - 1));
    if (tt == 0) continue;
    int ans = a[2][i].second + tt;
    if (ans > res) res = ans;
  }
}
void xuli3() {
  int ans1 = 0, ans2 = 0;
  for (int i = 1; i <= d1; i++) {
    if (a[1][i].second > ans1 && a[1][i].first <= c) ans1 = a[1][i].second;
  }
  for (int i = 1; i <= d2; i++) {
    if (a[2][i].second > ans2 && a[2][i].first <= d) ans2 = a[2][i].second;
  }
  if (ans1 == 0 || ans2 == 0) return;
  if (ans1 + ans2 > res) res = ans1 + ans2;
}
int main() {
  cin >> n >> c >> d;
  for (int i = 1; i <= n; i++) {
    int b, p;
    char c;
    cin >> b >> p >> c;
    if (c == 'C')
      a[1][++d1] = make_pair(p, b);
    else
      a[2][++d2] = make_pair(p, b);
  }
  if (d1 > 1) xuli1();
  if (d2 > 1) xuli2();
  xuli3();
  cout << res;
}
