#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();
  }
}

### Prompt

Please formulate a cpp solution to the following problem:

Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.

Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.

Input

The first line contains three integers n, c and d (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100 000) — the number of fountains, the number of coins and diamonds Arkady has.

The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 ≤ bi, pi ≤ 100 000) — the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.

Output

Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.

Examples

Input

3 7 6
10 8 C
4 3 C
5 6 D


Output

9


Input

2 4 5
2 5 C
2 1 D


Output

0


Input

3 10 10
5 5 C
5 5 C
10 11 D


Output

10

Note

In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.

In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins. 

### Response

```cpp
#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();
  }
}

```