# include <bits/stdc++.h>
using namespace std;
typedef long long lin;
typedef long double ld;
typedef pair < int, int > pii;
const int N = int(5e5) + 5;
const int inf = (int)1e9 + 7;
struct segtree{
int t[N * 4];
void upd(int v, int tl, int tr, int pos, int val){
if(tl == tr){
t[v] = max(t[v], val);
return;
}
int tm = (tl + tr) >> 1;
if(pos <= tm){
upd(v * 2, tl, tm, pos, val);
} else{
upd(v * 2 + 1, tm + 1, tr, pos, val);
}
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
int get(int v, int tl, int tr, int l, int r){
int tm = (tl + tr) >> 1;
if(tl == l && tr == r){
return t[v];
}
if(l > r){
return 0;
}
return max(get(v * 2, tl, tm, l, min(r, tm)), get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
int get(int l, int r){
return get(1, 1, (int)2e5 + 2, l, r);
}
void upd(int pos, int val){
upd(1, 1, (int)2e5 + 2, pos, val);
}
void clear_it(){
fill(t, t + N * 4, 0);
}
}t;
int n, c, d;
int ans = -1;
vector < pii > dia, coi;
void solve(vector < pii > c, int f){
vector < int > mx((int)c.size(), 0);
for(int i = 0; i < (int)c.size(); ++i){
mx[i] = max(i > 0 ? mx[i - 1] : 0, c[i].second);
}
for(int i = 0; i < (int)c.size(); ++i){
int j = lower_bound(c.begin(), c.begin() + i, make_pair(f - c[i].first + 1, -1)) - c.begin();
--j;
if(j >= 0){
ans = max(ans, mx[j] + c[i].second);
}
}
}
int main(){
cin >> n >> c >> d;
for(int i = 1; i <= n; ++i){
int x, y;
char e;
cin >> x >> y >> e;
if(e == 'C'){
coi.push_back(make_pair(y, x));
} else{
dia.push_back(make_pair(y, x));
}
}
sort(coi.begin(), coi.end());
sort(dia.begin(), dia.end());
solve(coi, c);
solve(dia, d);
int b1 = -1, b2 = -1;
for(auto i : coi){
if(i.first <= c){
b1 = max(b1, i.second);
}
}
for(auto i : dia){
if(i.first <= d){
b2 = max(b2, i.second);
}
}
if(b1 != -1 && b2 != -1){
ans = max(ans, b1 + b2);
}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CBnZXQoaW50IGwsIGludCByKXsKICAgIHJldHVybiBnZXQoMSwgMSwgKGludCkyZTUgKyAyLCBsLCByKTsKICB9CgogIHZvaWQgdXBkKGludCBwb3MsIGludCB2YWwpewogICAgdXBkKDEsIDEsIChpbnQpMmU1ICsgMiwgcG9zLCB2YWwpOwogIH0KCiAgdm9pZCBjbGVhcl9pdCgpewogICAgZmlsbCh0LCB0ICsgTiAqIDQsIDApOwogIH0KfXQ7CgppbnQgbiwgYywgZDsKaW50IGFucyA9IC0xOwp2ZWN0b3IgPCBwaWkgPiBkaWEsIGNvaTsKCnZvaWQgc29sdmUodmVjdG9yIDwgcGlpID4gYywgaW50IGYpewogIHZlY3RvciA8IGludCA+IG14KChpbnQpYy5zaXplKCksIDApOwogIGZvcihpbnQgaSA9IDA7IGkgPCAoaW50KWMuc2l6ZSgpOyArK2kpewogICAgbXhbaV0gPSBtYXgoaSA+IDAgPyBteFtpIC0gMV0gOiAwLCBjW2ldLnNlY29uZCk7CiAgfQogIGZvcihpbnQgaSA9IDA7IGkgPCAoaW50KWMuc2l6ZSgpOyArK2kpewogICAgaW50IGogPSBsb3dlcl9ib3VuZChjLmJlZ2luKCksIGMuYmVnaW4oKSArIGksIG1ha2VfcGFpcihmIC0gY1tpXS5maXJzdCArIDEsIC0xKSkgLSBjLmJlZ2luKCk7CiAgICAtLWo7CiAgICBpZihqID49IDApewogICAgICBhbnMgPSBtYXgoYW5zLCBteFtqXSArIGNbaV0uc2Vjb25kKTsKICAgIH0KICB9Cn0KCmludCBtYWluKCl7CiAgY2luID4+IG4gPj4gYyA+PiBkOwogIGZvcihpbnQgaSA9IDE7IGkgPD0gbjsgKytpKXsKICAgIGludCB4LCB5OwogICAgY2hhciBlOwogICAgY2luID4+IHggPj4geSA+PiBlOwogICAgaWYoZSA9PSAnQycpewogICAgICBjb2kucHVzaF9iYWNrKG1ha2VfcGFpcih5LCB4KSk7CiAgICB9IGVsc2V7CiAgICAgIGRpYS5wdXNoX2JhY2sobWFrZV9wYWlyKHksIHgpKTsKICAgIH0KICB9CiAgc29ydChjb2kuYmVnaW4oKSwgY29pLmVuZCgpKTsKICBzb3J0KGRpYS5iZWdpbigpLCBkaWEuZW5kKCkpOwogIHNvbHZlKGNvaSwgYyk7CiAgc29sdmUoZGlhLCBkKTsKICBpbnQgYjEgPSAtMSwgYjIgPSAtMTsKICBmb3IoYXV0byBpIDogY29pKXsKICAgIGlmKGkuZmlyc3QgPD0gYyl7CiAgICAgIGIxID0gbWF4KGIxLCBpLnNlY29uZCk7CiAgICB9CiAgfQogIGZvcihhdXRvIGkgOiBkaWEpewogICAgaWYoaS5maXJzdCA8PSBkKXsKICAgICAgYjIgPSBtYXgoYjIsIGkuc2Vjb25kKTsKICAgIH0KICB9CiAgaWYoYjEgIT0gLTEgJiYgYjIgIT0gLTEpewogICAgYW5zID0gbWF4KGFucywgYjEgKyBiMik7CiAgfQogIGlmKGFucyA9PSAtMSl7CiAgICBhbnMgPSAwOwogIH0KICBjb3V0IDw8IGFuczsKICByZXR1cm4gMDsKfQ==