#include <bits/stdc++.h>
using namespace std;
const int MX = 3e5 + 69;
const int inf = 1e9 + 5;
const long long mod = 1e9 + 7;
const long double eps = 1e-7;
long long po(long long a, long long b) {
  if (b == 0) {
    return 1;
  }
  long long x = po(a, b / 2);
  x *= x;
  if (b % 2) {
    x *= a;
  }
  return x;
}
vector<pair<int, int> > v[3];
int sgt[4 * MX][3];
void build(int x, int l, int r, int id) {
  if (l > r) {
    return;
  }
  if (l == r) {
    sgt[x][id] = v[id][l].first;
    return;
  }
  int mid = (l + r) / 2;
  build(2 * x, l, mid, id);
  build(2 * x + 1, mid + 1, r, id);
  sgt[x][id] = max(sgt[2 * x][id], sgt[2 * x + 1][id]);
}
int query(int x, int l, int r, int st, int en, int id) {
  if (l > r || l > en || r < st) {
    return -1e9;
  }
  if (l >= st && r <= en) {
    return sgt[x][id];
  }
  int mid = (l + r) / 2;
  int m1 = query(2 * x, l, mid, st, en, id);
  int m2 = query(2 * x + 1, mid + 1, r, st, en, id);
  return max(m1, m2);
}
bool cmp(pair<int, int> a, pair<int, int> b) { return (a.second < b.second); }
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  for (int i = 0; i < n; i++) {
    int va, p;
    char c;
    scanf("%d%d %c", &va, &p, &c);
    if (c == 'C') {
      v[0].push_back({va, p});
    } else {
      v[1].push_back({va, p});
    }
  }
  int ans = 0;
  sort(v[0].begin(), v[0].end(), cmp);
  sort(v[1].begin(), v[1].end(), cmp);
  bool ok = 0;
  if (v[0].size() > 1) {
    if (a >= v[0][0].second + v[0][1].second) {
      ok = 1;
    }
  }
  if (v[1].size() > 1) {
    if (b >= v[1][0].second + v[1][1].second) {
      ok = 1;
    }
  }
  if (!v[0].empty() && !v[1].empty()) {
    if (a >= v[0][0].second && b >= v[1][0].second) {
      ok = 1;
    }
  }
  if (!ok) {
    puts("0");
    return 0;
  }
  int l0 = v[0].size();
  int l1 = v[1].size();
  int p0 = l0 - 1;
  int p1 = l1 - 1;
  build(1, 0, p0, 0);
  build(1, 0, p1, 1);
  for (int i = 0; i < l0; i++) {
    int p = v[0][i].second;
    int va = v[0][i].first;
    if (p <= a) {
      int aa = a - p;
      while (v[0].size() && p0 > 0 && aa < v[0][p0].second) {
        p0--;
      }
      if (v[0].size() && p0 >= 0 && aa >= v[0][p0].second) {
        int q1 = -1e9, q2 = -1e9;
        if (p0 > i) q1 = query(1, 0, l0 - 1, i + 1, p0, 0);
        if (i - 1 >= 0) q2 = query(1, 0, l0 - 1, 0, min(i - 1, p0), 0);
        ans = max(ans, va + max(q1, q2));
      }
    } else {
      break;
    }
    while (v[1].size() && p1 > 0 && b < v[1][p1].second) {
      p1--;
    }
    if (v[1].size() && p1 >= 0 && b >= v[1][p1].second) {
      int q = -1e9;
      q = query(1, 0, l1 - 1, 0, p1, 1);
      ans = max(ans, va + q);
    }
  }
  p0 = l0 - 1;
  p1 = l1 - 1;
  for (int i = 0; i < l1; i++) {
    int p = v[1][i].second;
    int va = v[1][i].first;
    if (p <= b) {
      int bb = b - p;
      while (v[1].size() && p1 > 0 && bb < v[1][p1].second) {
        p1--;
      }
      if (v[1].size() && p1 >= 0 && bb >= v[1][p1].second) {
        int q1 = -1e9, q2 = -1e9;
        if (p1 > i) q1 = query(1, 0, l1 - 1, i + 1, p1, 1);
        if (i - 1 >= 0) q2 = query(1, 0, l1 - 1, 0, min(i - 1, p1), 1);
        ans = max(ans, va + max(q1, q2));
      }
    } else {
      break;
    }
    while (v[0].size() && p0 > 0 && a < v[0][p0].second) {
      p0--;
    }
    if (v[0].size() && p0 >= 0 && a >= v[0][p0].second) {
      int q = -1e9;
      q = query(1, 0, l0 - 1, 0, p0, 0);
      ans = max(ans, va + q);
    }
  }
  cout << ans;
  return 0;
}
