#include <bits/stdc++.h>
struct SFountain {
  size_t beauty;
  size_t price;
  SFountain() = default;
  SFountain(size_t b, size_t p) : beauty(b), price(p) {}
  static bool less_price(const SFountain &lhs, const SFountain &rhs) {
    return lhs.price < rhs.price;
  }
  static bool less_beauty(const SFountain &lhs, const SFountain &rhs) {
    return lhs.beauty < rhs.beauty;
  }
};
size_t maxSum(const std::vector<SFountain> &fountains, size_t max_price) {
  if (fountains.size() < 2) return 0;
  size_t max_beauty_total = 0;
  size_t max_beauty = 0;
  std::vector<SFountain> x;
  for (const SFountain &fountain : fountains) {
    auto upper = std::upper_bound(x.begin(), x.end(),
                                  SFountain(0, max_price - fountain.price),
                                  SFountain::less_price);
    if (upper != x.begin()) {
      --upper;
      max_beauty_total =
          std::max(max_beauty_total, fountain.beauty + upper->beauty);
    }
    if (max_beauty < fountain.beauty) {
      max_beauty = fountain.beauty;
      x.push_back(fountain);
    }
  }
  return max_beauty_total;
}
int main() {
  size_t n, c, d, maxC = 0, maxD = 0;
  std::cin >> n >> c >> d;
  std::vector<SFountain> coins;
  std::vector<SFountain> diamonds;
  coins.reserve(n);
  diamonds.reserve(n);
  for (size_t i = 0; i < n; ++i) {
    SFountain fountain;
    char price_type;
    std::cin >> fountain.beauty >> fountain.price >> price_type;
    if (price_type == 'C' && fountain.price <= c) {
      coins.push_back(fountain);
      maxC = std::max(maxC, fountain.beauty);
    } else if (price_type == 'D' && fountain.price <= d) {
      diamonds.push_back(fountain);
      maxD = std::max(maxD, fountain.beauty);
    }
  }
  std::sort(coins.begin(), coins.end(), SFountain::less_price);
  std::sort(diamonds.begin(), diamonds.end(), SFountain::less_price);
  size_t maxMixed = !coins.empty() && !diamonds.empty() ? maxC + maxD : 0;
  std::cout << std::max(std::max(maxSum(coins, c), maxSum(diamonds, d)),
                        maxMixed)
            << std::endl;
  return 0;
}
