#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
  long long res = 1LL;
  x = x % 1000000007;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res % 1000000007;
}
long long inv(long long n) { return power(n, 1000000007 - 2) % 1000000007; }
const long long N = 2e5 + 100;
long double eps = 1e-5;
bool equalTo(long double a, long double b) {
  if (fabs(a - b) <= eps)
    return true;
  else
    return false;
}
bool notEqual(long double a, long double b) {
  if (fabs(a - b) > eps)
    return true;
  else
    return false;
}
bool lessThan(long double a, long double b) {
  if (a + eps < b)
    return true;
  else
    return false;
}
bool lessThanEqual(long double a, long double b) {
  if (a < b + eps)
    return true;
  else
    return false;
}
bool greaterThan(long double a, long double b) {
  if (a > b + eps)
    return true;
  else
    return false;
}
bool greaterThanEqual(long double a, long double b) {
  if (a + eps > b)
    return true;
  else
    return false;
}
vector<pair<long long, long long> > v1, v2;
long long m1[100005], m2[100005];
void solve() {
  long long n, c, d, m;
  v1.push_back({0, 0});
  v2.push_back({0, 0});
  cin >> n >> c >> d;
  long long i, b, pr;
  char ch;
  for (i = 1; i <= n; i++) {
    cin >> b >> pr >> ch;
    if (ch == 'C') {
      if (pr <= c) v1.push_back({pr, b});
    } else {
      if (pr <= d) v2.push_back({pr, b});
    }
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  n = v1.size() - 1;
  m = v2.size() - 1;
  for (i = 1; i <= n; i++) m1[i] = max(m1[i - 1], v1[i].second);
  for (i = 1; i <= m; i++) m2[i] = max(m2[i - 1], v2[i].second);
  long long ans = -1;
  if (n && m) {
    ans = m1[n] + m2[m];
  }
  for (i = 2; i <= n; i++) {
    long long rem = c - v1[i].first;
    long long lo = 0, hi = i - 1;
    while (lo < hi) {
      long long mid = (lo + hi + 1) / 2;
      if (v1[mid].first <= rem)
        lo = mid;
      else
        hi = mid - 1;
    }
    if (lo) {
      ans = max(ans, m1[lo] + v1[i].second);
    }
  }
  for (i = 2; i <= m; i++) {
    long long rem = d - v2[i].first;
    long long lo = 0, hi = i - 1;
    while (lo < hi) {
      long long mid = (lo + hi + 1) / 2;
      if (v2[mid].first <= rem)
        lo = mid;
      else
        hi = mid - 1;
    }
    if (lo) ans = max(ans, m2[lo] + v2[i].second);
  }
  ans = max(ans, 0LL);
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  long long tc = 0;
  while (t--) {
    tc++;
    solve();
  }
}
