#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fll;
const int MX = 1e5 + 5;
int v[MX], w[MX];
char t[MX][2];
pair<int, int> p1[MX], p2[MX];
int sz1, sz2;
int solve1(int a, int b) {
  int mx1 = 0, mx2 = 0;
  for (int i = 1; i < sz1 + 1; ++i)
    if (p1[i].first <= a) mx1 = max(mx1, p1[i].second);
  for (int i = 1; i < sz2 + 1; ++i)
    if (p2[i].first <= b) mx2 = max(mx2, p2[i].second);
  return (mx1 > 0 && mx2 > 0) ? (mx1 + mx2) : 0;
}
int dp[MX][30];
void ST(int n) {
  for (int i = 1; i <= n; i++) dp[i][0] = v[i];
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 1; i + (1 << j) - 1 <= n; i++) {
      int a = dp[i][j - 1], b = dp[i + (1 << (j - 1))][j - 1];
      dp[i][j] = max(a, b);
    }
  }
}
int RMQ(int l, int r) {
  if (l > r) return 0;
  int k = 0;
  while ((1 << (k + 1)) <= r - l + 1) k++;
  int a = dp[l][k], b = dp[r - (1 << k) + 1][k];
  return max(a, b);
}
int solve2(pair<int, int> p[], int sz, int m) {
  if (sz <= 1) return 0;
  int ret = 0;
  sort(p + 1, p + sz + 1);
  for (int i = 1; i < sz + 1; ++i) w[i] = p[i].first;
  for (int i = 1; i < sz + 1; ++i) v[i] = p[i].second;
  for (int i = 2; i < sz + 1; ++i) assert(w[i] >= w[i - 1]);
  ST(sz);
  for (int i = 1, j = sz; i <= sz; i++) {
    while (w[i] + w[j] > m && j > i) j--;
    if (i < j) ret = max(ret, v[i] + RMQ(i + 1, j));
  }
  return ret;
}
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  for (int i = 1; i < n + 1; ++i) scanf("%d%d%s", &v[i], &w[i], t[i]);
  for (int i = 1; i < n + 1; ++i) {
    if (t[i][0] == 'C')
      p1[++sz1] = pair<int, int>(w[i], v[i]);
    else
      p2[++sz2] = pair<int, int>(w[i], v[i]);
  }
  int ans = solve1(a, b);
  ans = max(ans, solve2(p1, sz1, a));
  ans = max(ans, solve2(p2, sz2, b));
  cout << ans << endl;
  return 0;
}
