#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 69;
const long long mod = 1e9 + 7;
string s;
long long n, m, k;
long long x, y;
char z;
vector<pair<pair<long long, long long>, long long> > a;
vector<long long> val;
long long minn[MAXN][2];
bool check(long long x, long long tar) {
  long long itr =
      lower_bound(val.begin(), val.end(), tar - a[x].first.first) - val.begin();
  itr = max(itr, x + 1);
  if (a[x].second == 1) {
    if (minn[itr][0] <= k || minn[itr][1] + a[x].first.second <= m) {
      return 1;
    }
    return 0;
  } else {
    if (minn[itr][1] <= m || minn[itr][0] + a[x].first.second <= k) {
      return 1;
    }
    return 0;
  }
}
void bin() {
  long long l = 0, r = 1e18, mid;
  while (l < r) {
    mid = (r - l) / 2 + l + 1;
    for (long long i = 0; i < n; i++) {
      if (a[i].second == 1 && a[i].first.second > m) continue;
      if (a[i].second == 0 && a[i].first.second > k) continue;
      if (check(i, mid)) {
        l = mid;
        goto s;
      }
    }
    r = mid - 1;
  s:;
  }
  cout << l;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> x >> y >> z;
    if (z == 'C') {
      a.push_back({{x, y}, 1});
    } else {
      a.push_back({{x, y}, 0});
    }
  }
  sort(a.begin(), a.end());
  for (long long i = 1; i < MAXN; i++) {
    minn[i][0] = INT_MAX;
    minn[i][1] = INT_MAX;
  }
  for (long long i = n - 1; i >= 0; i--) {
    if (a[i].second == 1) {
      minn[i][1] = min(minn[i + 1][1], a[i].first.second);
      minn[i][0] = minn[i + 1][0];
    } else {
      minn[i][1] = minn[i + 1][1];
      minn[i][0] = min(minn[i + 1][0], a[i].first.second);
    }
  }
  for (long long i = 0; i < n; i++) {
    val.push_back(a[i].first.first);
  }
  bin();
}
