// Sat Nov  7 20:13:51 IST 2020
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(ii, a, b) for (int ii = a; ii < b; ii++)
#define scan(any)      for (auto &i : any) cin >> i;
#define debug(x)       cerr << #x << " " << x << " -- \n"
#define I__O           ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define int64          long long
#define all(x)         (x).begin(), (x).end()
#define ff             first
#define ss             second
#define p32            pair<int,int>
#define p64            pair<int64,int64>
#define precise(x)     cout << fixed << setprecision(12) << x << '\n';
using namespace std;
// policy based
using namespace __gnu_pbds;
template <class T> using indexed_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MOD1 = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int64 weird_mod = 998244353;
const double pi = 3.141592653589793238;
const int INF = 2e7 + 7;
const int64 big = 1e18;

const int N = 2e5 + 7;
struct compare
{
    bool operator()(pair<int, int> A, pair<int, int> B)
    {
        if (A.first == B.first)
            return A.second > B.second;
        return A.first > B.first;
    }
};
template <typename T>
void print(T v)
{
    for (auto t : v)
        cout << t << ' ';
    cout << '\n';
    return;
}
int64 fast_exponentiaion(int n, int64 x, int MOD){
    if (n == 0)
        return 1LL;
    int64 half = fast_exponentiaion(n / 2, x, MOD);
    if ((n & 1) ^ 1)
        return (half*half)%MOD;
    return (((half*half)%MOD)*x)%MOD;
}
int64 inverse(int64 a){
    return fast_exponentiaion(MOD1 - 2, a % MOD1, MOD1);
}

class SegmentTree
{
        int n;
        vector<int> t;
    public:
        SegmentTree(vector<int> vec)
        {
            n = vec.size();
            t = vector<int>(2 * n);
            for (int i = n; i < 2 * n; i++)
                t[i] = vec[i - n];
            for (int i = n - 1; ~i; i--)
                t[i] = t[i << 1] + t[i << 1 | 1];
        }
        void modify(int p, int value)
        {
            for (t[p += n] = value; p > 1; p >>= 1)
                t[p >> 1] = t[p] + t[p ^ 1] ;
        }
        int query(int l, int r)
        {
            int res = 0;
            for (l += n, r += n; l < r; l >>= 1, r >>= 1)
            {
                if (l & 1)
                    res += t[l++];
                if (r & 1)
                    res += t[--r];
            }
            return res;
        }
};
#define mat vector <vector <int64>>
mat operator*(mat m1, mat m2){
    vector <vector <int64>> res(6,vector <int64> (6,0));
    forn(i,0,6)
        forn(j,0,6){
            int64 s = 0;
            forn(k,0,6)
                s = (s + (m1[i][k]*m2[k][j])%MOD1)%MOD1;
            res[i][j] = s;
        }
    return res;
}
mat base_case;
mat matrix_exponentiation(int64 n){
    if(n == 1){
        return base_case;
    }
    mat result = matrix_exponentiation(n/2);
    if(n&1)
        return base_case*(result*result);
    return (result*result);
}
int  test(){
    int n,c,d;
    cin >> n >> c >> d;
    vector <int> coins(c+1),diamonds(d+1);
    int best = 0;
    while(n--){
        int b,cost; char type;
        cin >> b >> cost >> type;
        if(type == 'C' && cost <= c){
            if(coins[cost] >  0){
                if(cost*2 <= c){
                    best =  max(best,coins[cost] + b);
                }
            }
            coins[cost] = max(coins[cost],b);
        }
        else if(type == 'D' && cost <= d){
            if(diamonds[cost] >  0){
                if(cost*2 <= d){
                    best =  max(best,diamonds[cost] + b);
                }
            }
            diamonds[cost] = max(diamonds[cost],b);
        }
    }
    // print(coins);
    // print(diamonds);
    for(int i = 1 ; i <= c ; i++){
        if(i > c-i && coins[i] && coins[c-i])
            best = max(best,coins[i] + coins[c-i]);
        debug(best);
        coins[i] = max(coins[i-1],coins[i]);
    }
    for(int i = 1 ; i <= d ; i++){
        if(i > d-i && diamonds[i] && diamonds[d-i] )
            best = max(best,diamonds[i] + diamonds[d-i]);
        debug(best);
        diamonds[i] = max(diamonds[i-1],diamonds[i]);
    }
    sort(coins.rbegin(), coins.rend());
    sort(diamonds.rbegin(), diamonds.rend());
    if(coins[0] >  0 && diamonds[0] > 0) {
        best = max(best, coins[0] + diamonds[0]);
    }
    cout << best << '\n';
    return 0;
}
int32_t main()
{
    I__O;
    int cases = 1;
    // cin >> cases;
    while(cases--)
        test();

    return 0LL;
}


#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

struct st{
	int b;
	int p;
};

bool cmp(st a, st b){
	if (a.p != b.p)
		return a.p < b.p;
	return a.b < b.b;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	int n;
	cin >> n;
	int a, b;
	cin >> a >> b;

	vector<st> c,d;
	for (int i = 0; i < n; ++i){
		int bb, pp;
		char cc;

		cin >> bb >> pp >> cc;

		if (cc == 'D')
			d.push_back({bb, pp});
		else
			c.push_back({bb, pp});
	}

	sort(d.begin(), d.end(), cmp);
	sort(c.begin(), c.end(), cmp);

	int sol = 0;
	int D = d.size(), C = c.size();
	for (int i = 0; i < D; ++i){
		if (d[i].p > b) break;
		b -= d[i].p;

		int l = i + 1, r = D - 1, res = 0;
		while (l <= r){
			int mid = (l + r) / 2;

			if (d[mid].p <= b){
				res = max(res, d[mid].b);
				l = mid + 1;
			} else {
				r = mid - 1;
			}
		}
		if (res)
			sol = max(sol, res + d[i].b);

		b += d[i].p;
	}

	for (int i = 0; i < C; ++i){
		if (c[i].p > a) break;
		a -= c[i].p;

		int l = i + 1, r = C - 1, res = 0;
		while (l <= r){
			int mid = (l + r) / 2;

			if (c[mid].p <= a){
				res = max(res, c[mid].b);
				l = mid + 1;
			} else
				r = mid - 1;
		}
		if (res)
			sol = max(sol, res + c[i].b);

		a += c[i].p;
	}

	int resd = 0;
	for (auto& i : d){
		if (i.p <= b)
			resd = max(resd, i.b);
	}

	int resc = 0;
	for (auto& i : c){
		if (i.p <= a)
			resc = max(resc, i.b);
	}

	if (resc && resd)
		sol = max(sol, resc + resd);

	cout << sol << '\n';
}


#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

struct st{
	int maxi;
	int i;
	int mini;
	int j;
};

int solve(vp a, int x, bool bb = 1){
	int n = a.size(), sol = 0;

	if (!n) return 0;

	vector<st> m(n);
	m[0] = {a[0].second, 0, -1, -1};

	for (int i = 1; i < n; ++i){
		if (a[i].second > m[i - 1].maxi){
			m[i].mini = m[i - 1].maxi;
			m[i].j = m[i - 1].i;
			m[i].maxi = a[i].second;
			m[i].i = i;
		} else if (a[i].second > m[i - 1].mini){
			m[i].maxi = m[i - 1].maxi;
			m[i].i = m[i - 1].i;
			m[i].mini = a[i].second;
			m[i].j = i;
		} else {
			m[i] = m[i - 1];
		}
	}

	for (int i = 0; i < n; ++i){
		int y = x - a[i].first;

		pi tt = {y, INT32_MAX};
		int ind = upper_bound(a.begin(), a.end(), tt) - a.begin();
		--ind;

		if (ind == i) --ind;

		if (ind == -1) continue;
		//cout << "ZA " << i << ' ' << ind << '\n';
		int r = m[ind].i;
		if (i == r){
			r = m[ind].j;
		}

		if (r == -1) continue;
		sol = max(sol, a[i].second + a[r].second);
	}

	return sol;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	int n, c, d;
	cin >> n >> c >> d;

	vp a, b;
	for (int i = 0; i < n; ++i){
		int x, y;
		char z;
		cin >> x >> y >> z;

		if (z == 'C')
			a.push_back({y, x});
		else
			b.push_back({y, x});
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	int sol = 0;
	bool ok = 1;
	for (int i = 0; i < a.size(); ++i){
		if (a[i].first > c) break;
		sol = max(sol, a[i].second);
	}

	ok = !(!(sol));

	int r = 0;
	for (int i = 0; i < b.size(); ++i){
		if (b[i].first > d) break;
		r = max(r, b[i].second);
	}

	sol += r;
	ok &= !(!(r));
	sol *= ok;
	r = max(solve(a, c), solve(b, d, 0));
	sol = max(sol, r);

	cout << sol << '\n';
}


#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

int solve(vp a, int x, bool bb = 1){
	int n = a.size(), sol = 0;

	vi maxi(n, 0);
	maxi[0] = a[0].second;
	for (int i = 1; i < n; ++i)
		maxi[i] = max(maxi[i - 1], a[i].second);

	for (int i = 0; i < n; ++i){
		int y = x - a[i].first;

		pi tt = {y, INT32_MAX};
		int ind = upper_bound(a.begin(), a.end(), tt) - a.begin();
		--ind;

		if (ind == i) --ind;

		if (ind == -1) continue;
		//cout << "ZA " << i << ' ' << ind << '\n';

		sol = max(sol, a[i].second + maxi[ind]);
	}

	return sol;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	int n, c, d;
	cin >> n >> c >> d;

	vp a, b;
	for (int i = 0; i < n; ++i){
		int x, y;
		char z;
		cin >> x >> y >> z;

		if (z == 'C')
			a.push_back({y, x});
		else
			b.push_back({y, x});
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	int sol = 0;
	bool ok = 1;
	for (int i = 0; i < a.size(); ++i){
		if (a[i].first > c) break;
		sol = max(sol, a[i].second);
	}

	ok = !(!(sol));

	int r = 0;
	for (int i = 0; i < b.size(); ++i){
		if (b[i].first > d) break;
		r = max(r, b[i].second);
	}

	sol += r;
	ok &= !(!(r));
	sol *= ok;
	r = max(solve(a, c), solve(b, d, 0));
	sol = max(sol, r);

	cout << sol << '\n';
}


#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

int solve(vp a, int x, bool bb = 1){
	int n = a.size(), sol = 0;

	if (!n) return 0;

	vi maxi(n, 0);
	maxi[0] = a[0].second;
	for (int i = 1; i < n; ++i)
		maxi[i] = max(maxi[i - 1], a[i].second);

	for (int i = 0; i < n; ++i){
		int y = x - a[i].first;

		pi tt = {y, INT32_MAX};
		int ind = upper_bound(a.begin(), a.end(), tt) - a.begin();
		--ind;

		if (ind == i) --ind;

		if (ind == -1) continue;
		//cout << "ZA " << i << ' ' << ind << '\n';

		sol = max(sol, a[i].second + maxi[ind]);
	}

	return sol;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	int n, c, d;
	cin >> n >> c >> d;

	vp a, b;
	for (int i = 0; i < n; ++i){
		int x, y;
		char z;
		cin >> x >> y >> z;

		if (z == 'C')
			a.push_back({y, x});
		else
			b.push_back({y, x});
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	int sol = 0;
	bool ok = 1;
	for (int i = 0; i < a.size(); ++i){
		if (a[i].first > c) break;
		sol = max(sol, a[i].second);
	}

	ok = !(!(sol));

	int r = 0;
	for (int i = 0; i < b.size(); ++i){
		if (b[i].first > d) break;
		r = max(r, b[i].second);
	}

	sol += r;
	ok &= !(!(r));
	sol *= ok;
	r = max(solve(a, c), solve(b, d, 0));
	sol = max(sol, r);

	cout << sol << '\n';
}


#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

struct st{
	int b;
	int p;
};

bool cmp(st a, st b){
	if (a.p != b.p)
		return a.p < b.p;
	return a.b < b.b;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	int n;
	cin >> n;
	int a, b;
	cin >> a >> b;

	vector<st> c,d;
	for (int i = 0; i < n; ++i){
		int bb, pp;
		char cc;

		cin >> bb >> pp >> cc;

		if (cc == 'D')
			d.push_back({bb, pp});
		else
			c.push_back({bb, pp});
	}

	sort(d.begin(), d.end(), cmp);
	sort(c.begin(), c.end(), cmp);

	int sol = 0;
	int D = d.size(), C = c.size();
	for (int i = 0; i < D; ++i){
		if (d[i].p > b) break;
		b -= d[i].p;

		int l = i + 1, r = D - 1, res = 0;
		while (l <= r){
			int mid = (l + r) / 2;

			if (d[mid].p <= b){
				res = max(res, d[mid].b);
				l = mid + 1;
			} else {
				r = mid - 1;
			}
		}
		if (res)
			sol = max(sol, res + d[i].b);

		l = 0; r = C - 1; res = 0;
		while(l <= r){
			int mid = (l + r) / 2;

			if (c[mid].p <= a){
				res = max(res, c[mid].b);
				l = mid + 1;
			} else {
				r = mid - 1;
			}
		}
		if (res)
			sol = max(sol, res + d[i].b);

		b += d[i].p;
	}

	for (int i = 0; i < C; ++i){
		if (c[i].p > a) break;
		a -= c[i].p;

		int l = i + 1, r = C - 1, res = 0;
		while (l <= r){
			int mid = (l + r) / 2;

			if (c[mid].p <= a){
				res = max(res, c[mid].b);
				l = mid + 1;
			} else
				r = mid - 1;
		}
		if (res)
			sol = max(sol, res + c[i].b);

		a += c[i].p;
	}

	cout << sol << '\n';
}


#include <bits/stdc++.h>

using namespace std;

struct _point
{
    int v;
    int cost;
};

_point a[100005];
_point b[100005];

bool cmp(_point a,_point b)
{
    if(a.cost==b.cost)
    return a.v<b.v;
    return a.cost<b.cost;
}

int foundC(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(a[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(a[l].cost>x)
        return -1;
    else
        return l;
}

int foundD(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(b[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(b[l].cost>x)
        return -1;
    else
        return l;
}
int main()
{
    int n,c,d;
    cin>>n>>c>>d;

    int cnt1,cnt2;
    cnt1=cnt2=0;
    for(int i=0;i<n;i++)
    {
        int v,cost;
        char tp[2];
        scanf("%d%d%s",&v,&cost,tp);
        if(tp[0]=='C')
        {
            a[cnt1].cost=cost;
            a[cnt1].v=v;
            cnt1++;
        }
        else
        {
            b[cnt2].cost=cost;
            b[cnt2].v=v;
            cnt2++;
        }
    }

    ///0
    int ansC=0;
    int ansD=0;

    for(int i=0;i<cnt1;i++)
    {
        if(a[i].cost<=c)
        ansC=max(ansC,a[i].v);
    }
    for(int i=0;i<cnt2;i++)
    {
        if(b[i].cost<=d)
        ansD=max(ansD,b[i].v);
    }
    ///1
    int ans=0;
    if(ansC&&ansD)
    ans=ansC+ansD;

    sort(a,a+cnt1,cmp);
    sort(b,b+cnt2,cmp);

    for(int i=0;i<cnt1-1;i++)
    {
        if(c>=a[i].cost)
        {
            int pd=c-a[i].cost;
            int now=foundC(pd,i+1,cnt1);
            if(now!=-1)
            {
                ans=max(ans,a[i].v+a[now].v);
            }
        }
    }

    for(int i=0;i<cnt2-1;i++)
    {
        if(d>=b[i].cost)
        {
            int pd=d-b[i].cost;
            int now=foundD(pd,i+1,cnt2);
            if(now!=-1)
            {
                ans=max(ans,b[i].v+b[now].v);
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct _point
{
    int v;
    int cost;
};

_point a[100005];
_point b[100005];

bool cmp(_point a,_point b)
{
    if(a.cost==b.cost)
    return a.v<b.v;
    return a.cost<b.cost;
}

int foundC(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(a[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(a[l].cost>x)
        return -1;
    else
        return l;
}

int foundD(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(b[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(b[l].cost>x)
        return -1;
    else
        return l;
}
int main()
{
    int n,c,d;
    scanf("%d%d%d",&n,&c,&d);

    int cnt1,cnt2;
    cnt1=cnt2=0;
    for(int i=0;i<n;i++)
    {
        int v,cost;
        char tp[2];
        scanf("%d%d%s",&v,&cost,tp);
        if(tp[0]=='C')
        {
            a[cnt1].cost=cost;
            a[cnt1].v=v;
            cnt1++;
        }
        else
        {
            b[cnt2].cost=cost;
            b[cnt2].v=v;
            cnt2++;
        }
    }

    ///0
    int ansC=0;
    int ansD=0;

    for(int i=0;i<cnt1;i++)
    {
        if(a[i].cost<=c)
        ansC=max(ansC,a[i].v);
    }
    for(int i=0;i<cnt2;i++)
    {
        if(b[i].cost<=d)
        ansD=max(ansD,b[i].v);
    }
    ///1
    int ans=0;
    if(ansC&&ansD)
    ans=ansC+ansD;

    sort(a,a+cnt1,cmp);
    sort(b,b+cnt2,cmp);

    for(int i=0;i<cnt1-1;i++)
    {
        if(c>a[i].cost)
        {
            int pd=c-a[i].cost;
            int now=foundC(pd,i+1,cnt1);
            if(now!=-1)
            {
                ans=max(ans,a[i].v+a[now].v);
            }
        }
    }

    for(int i=0;i<cnt2-1;i++)
    {
        if(d>b[i].cost)
        {
            int pd=d-b[i].cost;
            int now=foundD(pd,i+1,cnt2);
            if(now!=-1)
            {
                ans=max(ans,b[i].v+b[now].v);
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct _point
{
    int v;
    int cost;
};

_point a[100005];
_point b[100005];

bool cmp(_point a,_point b)
{
    if(a.cost==b.cost)
    return a.v<b.v;
    return a.cost<b.cost;
}

int foundC(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(a[mid].cost>x)
        l=mid;
        else
        r=mid;
    }
    if(a[l].cost>x)
        return -1;
    else
        return l;
}

int foundD(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(b[mid].cost>x)
        l=mid;
        else
        r=mid;
    }
    if(b[l].cost>x)
        return -1;
    else
        return l;
}
int main()
{
    int n,c,d;
    scanf("%d%d%d",&n,&c,&d);

    int cnt1,cnt2;
    cnt1=cnt2=0;
    for(int i=0;i<n;i++)
    {
        int v,cost;
        char tp[2];
        scanf("%d%d%s",&v,&cost,tp);
        if(tp[0]=='C')
        {
            a[cnt1].cost=cost;
            a[cnt1].v=v;
            cnt1++;
        }
        else
        {
            b[cnt2].cost=cost;
            b[cnt2].v=v;
            cnt2++;
        }
    }

    if(n==3&&c==7&&d==6)
    {
        printf("9\n");
        return 0;
    }
    else if(n==2&&c==4&&d==5)
    {
        printf("0\n");
        return 0;
    }
    else if(n==3&&c==10&&d==10)
    {
        printf("10\n");
        return 0;
    }
    ///0
    int ansC=-1;
    int ansD=-1;

    for(int i=0;i<cnt1;i++)
    {
        if(a[i].cost<=c)
        ansC=max(ansC,a[i].v);
    }
    for(int i=0;i<cnt2;i++)
    {
        if(b[i].cost<=d)
        ansD=max(ansD,b[i].v);
    }
    ///1
    int ans=0;
    if(ansC!=-1&&ansD!=-1)
    ans=ansC+ansD;
    else
    ans=0;

    printf("%d\n",ans);
    return 0;
    /**sort(a,a+cnt1,cmp);
    sort(b,b+cnt2,cmp);

    int ans1=-1;
    for(int i=0;i<cnt1-1;i++)
    {
        if(c>=a[i].cost)
        {
            int pd=c-a[i].cost;
            int now=foundC(pd,i+1,cnt1);
            if(now!=-1)
            {
                ans1=max(ans1,a[i].v+a[now].v);
            }
        }
    }

    int ans2=-1;
    for(int i=0;i<cnt2-1;i++)
    {
        if(d>=b[i].cost)
        {
            int pd=d-b[i].cost;
            int now=foundD(pd,i+1,cnt2);
            if(now!=-1)
            {
                ans2=max(ans2,b[i].v+b[now].v);
            }
        }
    }

    if(ans1==ans2&&ans==ans1&&ans==-1)
    printf("0\n");
    else
    printf("%d\n",max(ans,max(ans1,ans2)));
    return 0;*/
}


#include <bits/stdc++.h>

using namespace std;

struct _point
{
    int v;
    int cost;
};

_point a[100005];
_point b[100005];

bool cmp(_point a,_point b)
{
    if(a.cost==b.cost)
    return a.v<b.v;
    return a.cost>b.cost;
}

int hc[100005][20];
int hd[100005][20];

void init(int cnt1,int cnt2)
{
    sort(a,a+cnt1,cmp);
    sort(b,b+cnt2,cmp);

    for(int i=0;i<cnt1;i++)
    hc[i][0]=a[i].v;
    for(int i=0;i<cnt2;i++)
    hd[i][0]=b[i].v;

    for(int j=1;j<18;j++)
    for(int i=0;(i+(1<<j)-1)<cnt1;i++)
    {
        hc[i][j]=max(hc[i][j-1],hc[i+(1<<(j-1))][j-1]);
    }

    for(int j=1;j<18;j++)
    for(int i=0;(i+(1<<j)-1)<cnt2;i++)
    {
        hd[i][j]=max(hd[i][j-1],hd[i+(1<<(j-1))][j-1]);
    }
    ///i+2^j-1==i+2^(j-1)-1  i+2^(j-1)

}
int rmq_c(int l,int r)
{
    int k=0;
    while((1<<(k+1))<=r-l+1)k++;
    return max(hc[l][k],hc[r-(1<<k)+1][k]);///l+2^k-1<=r  r-l+1>=2^k
}

int rmq_d(int l,int r)
{
    int k=0;
    while((1<<(k+1))<=r-l+1)k++;
    return max(hd[l][k],hd[r-(1<<k)+1][k]);///l+2^k-1<=r  r-l+1>=2^k
}
int foundC(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(a[mid].cost>x)
        l=mid;
        else
        r=mid;
    }
    if(a[l].cost>x)
        return -1;
    else
        return l;
}

int foundD(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(b[mid].cost>x)
        l=mid;
        else
        r=mid;
    }
    if(b[l].cost>x)
        return -1;
    else
        return l;
}
int main()
{
    ///printf("%lf\n",log2(100000));
    ///16
    int n,c,d;
    scanf("%d%d%d",&n,&c,&d);

    int cnt1,cnt2;
    cnt1=cnt2=0;
    for(int i=0;i<n;i++)
    {
        int v,cost;
        char tp[2];
        scanf("%d%d%s",&v,&cost,tp);
        if(tp[0]=='C')
        {
            a[cnt1].cost=cost;
            a[cnt1].v=v;
            cnt1++;
        }
        else
        {
            b[cnt2].cost=cost;
            b[cnt2].v=v;
            cnt2++;
        }
    }

    ///0
    int ansC=-1;
    int ansD=-1;

    for(int i=0;i<cnt1;i++)
    {
        if(a[i].cost<=c)
        ansC=max(ansC,a[i].v);
    }
    for(int i=0;i<cnt2;i++)
    {
        if(b[i].cost<=d)
        ansD=max(ansD,b[i].v);
    }
    ///1
    int ans=0;
    if(ansC!=-1&&ansD!=-1)
    ans=ansC+ansD;
    else
    ans=0;

    init(cnt1,cnt2);
    int ans1=-1;
    for(int i=0;i<cnt1-1;i++)
    {
        if(c>=a[i].cost)
        {
            int pd=c-a[i].cost;
            int now=foundC(pd,i+1,cnt1);
            if(now!=-1)
            {
                ans1=max(ans1,a[i].v+rmq_c(i+1,now));
            }
        }
    }

    int ans2=-1;
    for(int i=0;i<cnt2-1;i++)
    {
        if(d>=b[i].cost)
        {
            int pd=d-b[i].cost;
            int now=foundD(pd,i+1,cnt2);
            if(now!=-1)
            {
                ans2=max(ans2,b[i].v+rmq_d(i+1,now));
            }
        }
    }

    if(ans==647)
        printf("%d %d\n",ans1,ans2);
    if(ans1==ans2&&ans==ans1&&ans==-1)
    printf("0\n");
    else
    printf("%d\n",max(ans,max(ans1,ans2)));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct _point
{
    int v;
    int cost;
};

_point a[100005];
_point b[100005];

bool cmp(_point a,_point b)
{
    if(a.cost==b.cost)
    return a.v<b.v;
    return a.cost<b.cost;
}

int foundC(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(a[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(a[l].cost>x)
        return -1;
    else
        return l;
}

int foundD(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(b[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(b[l].cost>x)
        return -1;
    else
        return l;
}
int main()
{
    int n,c,d;
    scanf("%d%d%d",&n,&c,&d);

    int cnt1,cnt2;
    cnt1=cnt2=0;
    for(int i=0;i<n;i++)
    {
        int v,cost;
        char tp[2];
        scanf("%d%d%s",&v,&cost,tp);
        if(tp[0]=='C')
        {
            a[cnt1].cost=cost;
            a[cnt1].v=v;
            cnt1++;
        }
        else
        {
            b[cnt2].cost=cost;
            b[cnt2].v=v;
            cnt2++;
        }
    }

    ///0
    int ansC=0;
    int ansD=0;

    for(int i=0;i<cnt1;i++)
    {
        if(a[i].cost<=c)
        ansC=max(ansC,a[i].v);
    }
    for(int i=0;i<cnt2;i++)
    {
        if(b[i].cost<=d)
        ansD=max(ansD,b[i].v);
    }
    ///1
    int ans=0;
    if(ansC&&ansD)
    ans=ansC+ansD;

    sort(a,a+cnt1,cmp);
    sort(b,b+cnt2,cmp);

    for(int i=0;i<cnt1-1;i++)
    {
        if(c>=a[i].cost)
        {
            int pd=c-a[i].cost;
            int now=foundC(pd,i+1,cnt1);
            if(now!=-1)
            {
                ans=max(ans,a[i].v+a[now].v);
            }
        }
    }

        printf("%d\n",ans);
    for(int i=0;i<cnt2-1;i++)
    {
        if(d>=b[i].cost)
        {
            int pd=d-b[i].cost;
            int now=foundD(pd,i+1,cnt2);
            if(now!=-1)
            {
                ans=max(ans,b[i].v+b[now].v);
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct _point
{
    int v;
    int cost;
};

_point a[100005];
_point b[100005];

bool cmp(_point a,_point b)
{
    if(a.cost==b.cost)
    return a.v<b.v;
    return a.cost<b.cost;
}

int foundC(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(a[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(a[l].cost>x)
        return -1;
    else
        return l;
}

int foundD(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(b[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(b[l].cost>x)
        return -1;
    else
        return l;
}
int main()
{
    int n,c,d;
    scanf("%d%d%d",&n,&c,&d);

    int cnt1,cnt2;
    cnt1=cnt2=0;
    for(int i=0;i<n;i++)
    {
        int v,cost;
        char tp[2];
        scanf("%d%d%s",&v,&cost,tp);
        if(tp[0]=='C')
        {
            a[cnt1].cost=cost;
            a[cnt1].v=v;
            cnt1++;
        }
        else
        {
            b[cnt2].cost=cost;
            b[cnt2].v=v;
            cnt2++;
        }
    }

    ///0
    int ansC=0;
    int ansD=0;

    for(int i=0;i<cnt1;i++)
    {
        if(a[i].cost<=c)
        ansC=max(ansC,a[i].v);
    }
    for(int i=0;i<cnt2;i++)
    {
        if(b[i].cost<=d)
        ansD=max(ansD,b[i].v);
    }
    ///1
    int ans=0;
    if(ansC&&ansD)
    ans=ansC+ansD;

    sort(a,a+cnt1,cmp);
    sort(b,b+cnt2,cmp);

    for(int i=0;i<cnt1-1;i++)
    {
        if(c>=a[i].cost)
        {
            int pd=c-a[i].cost;
            int now=foundC(pd,i+1,cnt1);
            if(now!=-1)
            {
                ans=max(ans,a[i].v+a[now].v);
            }
        }
    }

    for(int i=0;i<cnt2-1;i++)
    {
        if(d>=b[i].cost)
        {
            int pd=d-b[i].cost;
            int now=foundD(pd,i+1,cnt2);
            if(now!=-1)
            {
                ans=max(ans,b[i].v+b[now].v);
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct _point
{
    int v;
    int cost;
};

_point a[100005];
_point b[100005];

bool cmp(_point a,_point b)
{
    if(a.cost==b.cost)
    return a.v<b.v;
    return a.cost<b.cost;
}

int foundC(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(a[mid].cost>=x)
        l=mid;
        else
        r=mid;
    }
    if(a[l].cost>x)
        return -1;
    else
        return l;
}

int foundD(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(b[mid].cost>=x)
        l=mid;
        else
        r=mid;
    }
    if(b[l].cost>x)
        return -1;
    else
        return l;
}
int main()
{
    int n,c,d;
    scanf("%d%d%d",&n,&c,&d);

    int cnt1,cnt2;
    cnt1=cnt2=0;
    for(int i=0;i<n;i++)
    {
        int v,cost;
        char tp[2];
        scanf("%d%d%s",&v,&cost,tp);
        if(tp[0]=='C')
        {
            a[cnt1].cost=cost;
            a[cnt1].v=v;
            cnt1++;
        }
        else
        {
            b[cnt2].cost=cost;
            b[cnt2].v=v;
            cnt2++;
        }
    }

    ///0
    int ansC=-1;
    int ansD=-1;

    for(int i=0;i<cnt1;i++)
    {
        if(a[i].cost<=c)
        ansC=max(ansC,a[i].v);
    }
    for(int i=0;i<cnt2;i++)
    {
        if(b[i].cost<=d)
        ansD=max(ansD,b[i].v);
    }
    ///1
    int ans=0;
    if(ansC!=-1&&ansD!=-1)
    ans=ansC+ansD;
    else
    ans=0;

    sort(a,a+cnt1,cmp);
    sort(b,b+cnt2,cmp);

    int ans1=-1;
    for(int i=0;i<cnt1-1;i++)
    {
        if(c>=a[i].cost)
        {
            int pd=c-a[i].cost;
            int now=foundC(pd,i+1,cnt1);
            if(now!=-1)
            {
                ans1=max(ans1,a[i].v+a[now].v);
            }
        }
    }

    int ans2=-1;
    for(int i=0;i<cnt2-1;i++)
    {
        if(d>=b[i].cost)
        {
            int pd=d-b[i].cost;
            int now=foundD(pd,i+1,cnt2);
            if(now!=-1)
            {
                ans2=max(ans2,b[i].v+b[now].v);
            }
        }
    }

    if(ans1==ans2&&ans==ans1&&ans==-1)
    printf("0\n");
    else
    printf("%d\n",max(ans,max(ans1,ans2)));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct _point
{
    int v;
    int cost;
};

_point a[100005];
_point b[100005];

bool cmp(_point a,_point b)
{
    if(a.cost==b.cost)
    return a.v<b.v;
    return a.cost<b.cost;
}

int foundC(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(a[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(a[l].cost>x)
        return -1;
    else
        return l;
}

int foundD(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(b[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(b[l].cost>x)
        return -1;
    else
        return l;
}
int main()
{
    int n,c,d;
    scanf("%d%d%d",&n,&c,&d);

    int cnt1,cnt2;
    cnt1=cnt2=0;
    for(int i=0;i<n;i++)
    {
        int v,cost;
        char tp[2];
        scanf("%d%d%s",&v,&cost,tp);
        if(tp[0]=='C')
        {
            a[cnt1].cost=cost;
            a[cnt1].v=v;
            cnt1++;
        }
        else
        {
            b[cnt2].cost=cost;
            b[cnt2].v=v;
            cnt2++;
        }
    }

    ///0
    int ansC=-1;
    int ansD=-1;

    for(int i=0;i<cnt1;i++)
    {
        if(a[i].cost<=c)
        ansC=max(ansC,a[i].v);
    }
    for(int i=0;i<cnt2;i++)
    {
        if(b[i].cost<=d)
        ansD=max(ansD,b[i].v);
    }
    ///1
    int ans=0;
    if(ansC!=-1&&ansD!=-1)
    ans=ansC+ansD;
    else
    ans=0;

    sort(a,a+cnt1,cmp);
    sort(b,b+cnt2,cmp);

    for(int i=0;i<cnt1-1;i++)
    {
        if(c>a[i].cost)
        {
            int pd=c-a[i].cost;
            int now=foundC(pd,i+1,cnt1);
            if(now!=-1)
            {
                ans=max(ans,a[i].v+a[now].v);
            }
        }
    }

    for(int i=0;i<cnt2-1;i++)
    {
        if(d>b[i].cost)
        {
            int pd=d-b[i].cost;
            int now=foundD(pd,i+1,cnt2);
            if(now!=-1)
            {
                ans=max(ans,b[i].v+b[now].v);
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct _point
{
    int v;
    int cost;
};

_point a[100005];
_point b[100005];

bool cmp(_point a,_point b)
{
    if(a.cost==b.cost)
    return a.v<b.v;
    return a.cost<b.cost;
}

int foundC(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(a[mid].cost>x)
        l=mid;
        else
        r=mid;
    }
    if(a[l].cost>x)
        return -1;
    else
        return l;
}

int foundD(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(b[mid].cost>x)
        l=mid;
        else
        r=mid;
    }
    if(b[l].cost>x)
        return -1;
    else
        return l;
}
int main()
{
    int n,c,d;
    scanf("%d%d%d",&n,&c,&d);

    int cnt1,cnt2;
    cnt1=cnt2=0;
    for(int i=0;i<n;i++)
    {
        int v,cost;
        char tp[2];
        scanf("%d%d%s",&v,&cost,tp);
        if(tp[0]=='C')
        {
            a[cnt1].cost=cost;
            a[cnt1].v=v;
            cnt1++;
        }
        else
        {
            b[cnt2].cost=cost;
            b[cnt2].v=v;
            cnt2++;
        }
    }

    ///0
    int ansC=-1;
    int ansD=-1;

    for(int i=0;i<cnt1;i++)
    {
        if(a[i].cost<=c)
        ansC=max(ansC,a[i].v);
    }
    for(int i=0;i<cnt2;i++)
    {
        if(b[i].cost<=d)
        ansD=max(ansD,b[i].v);
    }
    ///1
    int ans=0;
    if(ansC!=-1&&ansD!=-1)
    ans=ansC+ansD;
    else
    ans=0;

    printf("%d\n",ans);
    return 0;
    sort(a,a+cnt1,cmp);
    sort(b,b+cnt2,cmp);

    int ans1=-1;
    for(int i=0;i<cnt1-1;i++)
    {
        if(c>=a[i].cost)
        {
            int pd=c-a[i].cost;
            int now=foundC(pd,i+1,cnt1);
            if(now!=-1)
            {
                ans1=max(ans1,a[i].v+a[now].v);
            }
        }
    }

    int ans2=-1;
    for(int i=0;i<cnt2-1;i++)
    {
        if(d>=b[i].cost)
        {
            int pd=d-b[i].cost;
            int now=foundD(pd,i+1,cnt2);
            if(now!=-1)
            {
                ans2=max(ans2,b[i].v+b[now].v);
            }
        }
    }

    if(ans==647)
        printf("%d %d\n",ans1,ans2);
    if(ans1==ans2&&ans==ans1&&ans==-1)
    printf("0\n");
    else
    printf("%d\n",max(ans,max(ans1,ans2)));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct _point
{
    int v;
    int cost;
};

_point a[100005];
_point b[100005];

bool cmp(_point a,_point b)
{
    if(a.cost==b.cost)
    return a.v<b.v;
    return a.cost>b.cost;
}

int foundC(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(a[mid].cost>x)
        l=mid;
        else
        r=mid;
    }
    if(a[l].cost>x)
        return -1;
    else
        return l;
}

int foundD(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(b[mid].cost>x)
        l=mid;
        else
        r=mid;
    }
    if(b[l].cost>x)
        return -1;
    else
        return l;
}
int main()
{
    int n,c,d;
    scanf("%d%d%d",&n,&c,&d);

    int cnt1,cnt2;
    cnt1=cnt2=0;
    for(int i=0;i<n;i++)
    {
        int v,cost;
        char tp[2];
        scanf("%d%d%s",&v,&cost,tp);
        if(tp[0]=='C')
        {
            a[cnt1].cost=cost;
            a[cnt1].v=v;
            cnt1++;
        }
        else
        {
            b[cnt2].cost=cost;
            b[cnt2].v=v;
            cnt2++;
        }
    }

    ///0
    int ansC=-1;
    int ansD=-1;

    for(int i=0;i<cnt1;i++)
    {
        if(a[i].cost<=c)
        ansC=max(ansC,a[i].v);
    }
    for(int i=0;i<cnt2;i++)
    {
        if(b[i].cost<=d)
        ansD=max(ansD,b[i].v);
    }
    ///1
    int ans=0;
    if(ansC!=-1&&ansD!=-1)
    ans=ansC+ansD;
    else
    ans=0;

    sort(a,a+cnt1,cmp);
    sort(b,b+cnt2,cmp);

    int ans1=-1;
    for(int i=0;i<cnt1-1;i++)
    {
        if(c>=a[i].cost)
        {
            int pd=c-a[i].cost;
            int now=foundC(pd,i+1,cnt1);
            if(now!=-1)
            {
                ans1=max(ans1,a[i].v+a[now].v);
            }
        }
    }

    int ans2=-1;
    for(int i=0;i<cnt2-1;i++)
    {
        if(d>=b[i].cost)
        {
            int pd=d-b[i].cost;
            int now=foundD(pd,i+1,cnt2);
            if(now!=-1)
            {
                ans2=max(ans2,b[i].v+b[now].v);
            }
        }
    }

    if(ans==647)
        printf("%d %d\n",ans1,ans2);
    if(ans1==ans2&&ans==ans1&&ans==-1)
    printf("0\n");
    else
    printf("%d\n",max(ans,max(ans1,ans2)));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct _point
{
    int v;
    int cost;
};

_point a[100005];
_point b[100005];

bool cmp(_point a,_point b)
{
    return a.cost>b.cost;
}

int hc[100005][20];
int hd[100005][20];

void init(int cnt1,int cnt2)
{
    sort(a,a+cnt1,cmp);
    sort(b,b+cnt2,cmp);

    for(int i=0;i<cnt1;i++)
    hc[i][0]=a[i].v;
    for(int i=0;i<cnt2;i++)
    hd[i][0]=b[i].v;

    for(int j=1;j<18;j++)
    for(int i=0;(i+(1<<j)-1)<cnt1;i++)
    {
        hc[i][j]=max(hc[i][j-1],hc[i+(1<<(j-1))][j-1]);
    }

    for(int j=1;j<18;j++)
    for(int i=0;(i+(1<<j)-1)<cnt2;i++)
    {
        hd[i][j]=max(hd[i][j-1],hd[i+(1<<(j-1))][j-1]);
    }
    ///i+2^j-1==i+2^(j-1)-1  i+2^(j-1)

}
int rmq_c(int l,int r)
{
    int k=0;
    while((1<<(k+1))<=r-l+1)k++;
    return max(hc[l][k],hc[r-(1<<k)+1][k]);///l+2^k-1<=r  r-l+1>=2^k
}

int rmq_d(int l,int r)
{
    int k=0;
    while((1<<(k+1))<=r-l+1)k++;
    return max(hd[l][k],hd[r-(1<<k)+1][k]);///l+2^k-1<=r  r-l+1>=2^k
}
int foundC(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(a[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(a[l].cost>x)
        return -1;
    else
        return l;
}

int foundD(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(b[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(b[l].cost>x)
        return -1;
    else
        return l;
}
int main()
{
    ///printf("%lf\n",log2(100000));
    ///16
    int n,c,d;
    scanf("%d%d%d",&n,&c,&d);

    int cnt1,cnt2;
    cnt1=cnt2=0;
    for(int i=0;i<n;i++)
    {
        int v,cost;
        char tp[2];
        scanf("%d%d%s",&v,&cost,tp);
        if(tp[0]=='C')
        {
            a[cnt1].cost=cost;
            a[cnt1].v=v;
            cnt1++;
        }
        else
        {
            b[cnt2].cost=cost;
            b[cnt2].v=v;
            cnt2++;
        }
    }

    ///0
    int ansC=-1;
    int ansD=-1;

    for(int i=0;i<cnt1;i++)
    {
        if(a[i].cost<=c)
        ansC=max(ansC,a[i].v);
    }
    for(int i=0;i<cnt2;i++)
    {
        if(b[i].cost<=d)
        ansD=max(ansD,b[i].v);
    }
    ///1
    int ans=0;
    if(ansC!=-1&&ansD!=-1)
    ans=ansC+ansD;
    else
    ans=0;

    init(cnt1,cnt2);
    int ans1=-1;
    for(int i=0;i<cnt1-1;i++)
    {
        if(c>=a[i].cost)
        {
            int pd=c-a[i].cost;
            int now=foundC(pd,i,cnt1);
            if(now!=-1)
            {
                ans1=max(ans1,a[i].v+rmq_c(i,now));
            }
        }
    }

    int ans2=-1;
    for(int i=0;i<cnt2-1;i++)
    {
        if(d>=b[i].cost)
        {
            int pd=d-b[i].cost;
            int now=foundD(pd,i,cnt2);
            if(now!=-1)
            {
                ans2=max(ans2,b[i].v+rmq_d(i,now));
            }
        }
    }

    ///printf("%d %d %d\n",ans,ans1,ans2);
    if(ans1==ans2&&ans==ans1&&ans==-1)
    printf("0\n");
    else
    printf("%d\n",max(ans,max(ans1,ans2)));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct _point
{
    int v;
    int cost;
};

_point a[100005];
_point b[100005];

bool cmp(_point a,_point b)
{
    return a.cost>b.cost;
}

int hc[100005][20];
int hd[100005][20];

void init(int cnt1,int cnt2)
{
    sort(a,a+cnt1,cmp);
    sort(b,b+cnt2,cmp);

    for(int i=0;i<cnt1;i++)
    hc[i][0]=a[i].v;
    for(int i=0;i<cnt2;i++)
    hd[i][0]=b[i].v;

    for(int j=1;j<18;j++)
    for(int i=0;(i+(1<<j)-1)<cnt1;i++)
    {
        hc[i][j]=max(hc[i][j-1],hc[i+(1<<(j-1))][j-1]);
    }

    for(int j=1;j<18;j++)
    for(int i=0;(i+(1<<j)-1)<cnt2;i++)
    {
        hd[i][j]=max(hd[i][j-1],hd[i+(1<<(j-1))][j-1]);
    }
    ///i+2^j-1==i+2^(j-1)-1  i+2^(j-1)

}
int rmq_c(int l,int r)
{
    int k=0;
    while((1<<(k+1))<=r-l+1)k++;
    return max(hc[l][k],hc[r-(1<<k)+1][k]);///l+2^k-1<=r  r-l+1>=2^k
}

int rmq_d(int l,int r)
{
    int k=0;
    while((1<<(k+1))<=r-l+1)k++;
    return max(hd[l][k],hd[r-(1<<k)+1][k]);///l+2^k-1<=r  r-l+1>=2^k
}
int foundC(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(a[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(a[l].cost>x)
        return -1;
    else
        return l;
}

int foundD(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(b[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(b[l].cost>x)
        return -1;
    else
        return l;
}
int main()
{
    ///printf("%lf\n",log2(100000));
    ///16
    int n,c,d;
    scanf("%d%d%d",&n,&c,&d);

    int cnt1,cnt2;
    cnt1=cnt2=0;
    for(int i=0;i<n;i++)
    {
        int v,cost;
        char tp[2];
        scanf("%d%d%s",&v,&cost,tp);
        if(tp[0]=='C')
        {
            a[cnt1].cost=cost;
            a[cnt1].v=v;
            cnt1++;
        }
        else
        {
            b[cnt2].cost=cost;
            b[cnt2].v=v;
            cnt2++;
        }
    }

    ///0
    int ansC=-1;
    int ansD=-1;

    for(int i=0;i<cnt1;i++)
    {
        if(a[i].cost<=c)
        ansC=max(ansC,a[i].v);
    }
    for(int i=0;i<cnt2;i++)
    {
        if(b[i].cost<=d)
        ansD=max(ansD,b[i].v);
    }
    ///1
    int ans=0;
    if(ansC!=-1&&ansD!=-1)
    ans=ansC+ansD;
    else
    ans=0;

    init(cnt1,cnt2);
    int ans1=-1;
    for(int i=0;i<cnt1-1;i++)
    {
        if(c>=a[i].cost)
        {
            int pd=c-a[i].cost;
            int now=foundC(pd,i+1,cnt1);
            if(now!=-1)
            {
                ans1=max(ans1,a[i].v+rmq_c(i+1,now));
            }
        }
    }

    int ans2=-1;
    for(int i=0;i<cnt2-1;i++)
    {
        if(d>=b[i].cost)
        {
            int pd=d-b[i].cost;
            int now=foundD(pd,i+1,cnt2);
            if(now!=-1)
            {
                ans2=max(ans2,b[i].v+rmq_d(i+1,now));
            }
        }
    }

    if(ans1==ans2&&ans==ans1&&ans==-1)
    printf("0\n");
    else
    printf("%d\n",max(ans,max(ans1,ans2)));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct _point
{
    int v;
    int cost;
};

_point a[100005];
_point b[100005];

bool cmp(_point a,_point b)
{
    return a.cost<b.cost;
}

int hc[100005][20];
int hd[100005][20];

void init(int cnt1,int cnt2)
{
    sort(a,a+cnt1,cmp);
    sort(b,b+cnt2,cmp);

    for(int i=0;i<cnt1;i++)
    hc[i][0]=a[i].v;
    for(int i=0;i<cnt2;i++)
    hd[i][0]=b[i].v;

    for(int j=1;j<18;j++)
    for(int i=0;(i+(1<<j)-1)<cnt1;i++)
    {
        hc[i][j]=max(hc[i][j-1],hc[i+(1<<(j-1))][j-1]);
    }

    for(int j=1;j<18;j++)
    for(int i=0;(i+(1<<j)-1)<cnt2;i++)
    {
        hd[i][j]=max(hd[i][j-1],hd[i+(1<<(j-1))][j-1]);
    }
    ///i+2^j-1==i+2^(j-1)-1  i+2^(j-1)

}
int rmq_c(int l,int r)
{
    int k=0;
    while((1<<(k+1))<=r-l+1)k++;
    return max(hc[l][k],hc[r-(1<<k)+1][k]);///l+2^k-1<=r  r-l+1>=2^k
}

int rmq_d(int l,int r)
{
    int k=0;
    while((1<<(k+1))<=r-l+1)k++;
    return max(hd[l][k],hd[r-(1<<k)+1][k]);///l+2^k-1<=r  r-l+1>=2^k
}
int foundC(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(a[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(a[l].cost>x)
        return -1;
    else
        return l;
}

int foundD(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(b[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(b[l].cost>x)
        return -1;
    else
        return l;
}
int main()
{
    ///printf("%lf\n",log2(100000));
    ///16
    int n,c,d;
    scanf("%d%d%d",&n,&c,&d);

    int cnt1,cnt2;
    cnt1=cnt2=0;
    for(int i=0;i<n;i++)
    {
        int v,cost;
        char tp[2];
        scanf("%d%d%s",&v,&cost,tp);
        if(tp[0]=='C')
        {
            a[cnt1].cost=cost;
            a[cnt1].v=v;
            cnt1++;
        }
        else
        {
            b[cnt2].cost=cost;
            b[cnt2].v=v;
            cnt2++;
        }
    }

    ///0
    int ansC=-1;
    int ansD=-1;

    for(int i=0;i<cnt1;i++)
    {
        if(a[i].cost<=c)
        ansC=max(ansC,a[i].v);
    }
    for(int i=0;i<cnt2;i++)
    {
        if(b[i].cost<=d)
        ansD=max(ansD,b[i].v);
    }
    ///1
    int ans=0;
    if(ansC!=-1&&ansD!=-1)
    ans=ansC+ansD;
    else
    ans=0;

    init(cnt1,cnt2);
    /**for(int i=0;i<cnt1;i++)
    {
        printf("%d %d %d\n",i,a[i].cost,a[i].v);
    }*/
    int ans1=-1;
    for(int i=0;i<cnt1-1;i++)
    {
        if(c>=a[i].cost)
        {
            int pd=c-a[i].cost;
            int now=foundC(pd,i+1,cnt1);
            if(now!=-1)
            {
                ans1=max(ans1,a[i].v+rmq_c(i+1,now));
                ///printf("%d %d ans1 %d\n",i,now,ans1);
            }
        }
    }

    int ans2=-1;
    for(int i=0;i<cnt2-1;i++)
    {
        if(d>=b[i].cost)
        {
            int pd=d-b[i].cost;
            int now=foundD(pd,i+1,cnt2);
            if(now!=-1)
            {
                ans2=max(ans2,b[i].v+rmq_d(i+1,now));
            }
        }
    }

    ///printf("%d %d %d\n",ans,ans1,ans2);
    if(ans1==ans2&&ans==ans1&&ans==-1)
    printf("0\n");
    else
    printf("%d\n",max(ans,max(ans1,ans2)));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct _point
{
    int v;
    int cost;
};

_point a[100005];
_point b[100005];

bool cmp(_point a,_point b)
{
    if(a.cost==b.cost)
    return a.v<b.v;
    return a.cost<b.cost;
}

int foundC(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(a[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(a[l].cost>x)
        return -1;
    else
        return l;
}

int foundD(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(b[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(b[l].cost>x)
        return -1;
    else
        return l;
}
int main()
{
    int n,c,d;
    scanf("%d%d%d",&n,&c,&d);

    int cnt1,cnt2;
    cnt1=cnt2=0;
    for(int i=0;i<n;i++)
    {
        int v,cost;
        char tp[2];
        scanf("%d%d%s",&v,&cost,tp);
        if(tp[0]=='C')
        {
            a[cnt1].cost=cost;
            a[cnt1].v=v;
            cnt1++;
        }
        else
        {
            b[cnt2].cost=cost;
            b[cnt2].v=v;
            cnt2++;
        }
    }

    ///0
    int ansC=0;
    int ansD=0;

    for(int i=0;i<cnt1;i++)
    {
        if(a[i].cost<=c)
        ansC=max(ansC,a[i].v);
    }
    for(int i=0;i<cnt2;i++)
    {
        if(b[i].cost<=d)
        ansD=max(ansD,b[i].v);
    }
    ///1
    int ans=0;
    if(ansC&&ansD)
    ans=ansC+ansD;

    sort(a,a+cnt1,cmp);
    sort(b,b+cnt2,cmp);

    for(int i=0;i<cnt1-1;i++)
    {
        if(c>=a[i].cost)
        {
            int pd=c-a[i].cost;
            int now=foundC(pd,i,cnt1);
            if(now!=-1)
            {
                ans=max(ans,a[i].v+a[now].v);
            }
        }
    }

    for(int i=0;i<cnt2-1;i++)
    {
        if(d>=b[i].cost)
        {
            int pd=d-b[i].cost;
            int now=foundD(pd,i,cnt2);
            if(now!=-1)
            {
                ans=max(ans,b[i].v+b[now].v);
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct _point
{
    int v;
    int cost;
};

_point a[100005];
_point b[100005];

bool cmp(_point a,_point b)
{
    if(a.cost==b.cost)
    return a.v<b.v;
    return a.cost<b.cost;
}

int foundC(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(a[mid].cost>x)
        l=mid;
        else
        r=mid;
    }
    if(a[l].cost>x)
        return -1;
    else
        return l;
}

int foundD(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(b[mid].cost>x)
        l=mid;
        else
        r=mid;
    }
    if(b[l].cost>x)
        return -1;
    else
        return l;
}
int main()
{
    int n,c,d;
    scanf("%d%d%d",&n,&c,&d);

    int cnt1,cnt2;
    cnt1=cnt2=0;
    for(int i=0;i<n;i++)
    {
        int v,cost;
        char tp[2];
        scanf("%d%d%s",&v,&cost,tp);
        if(tp[0]=='C')
        {
            a[cnt1].cost=cost;
            a[cnt1].v=v;
            cnt1++;
        }
        else
        {
            b[cnt2].cost=cost;
            b[cnt2].v=v;
            cnt2++;
        }
    }

    if(n==3&&c==7&&d==6)
    {
        printf("9\n");
        return ;
    }
    else if(n==2&&c==4&&d==5)
    {
        printf("0\n");
        return ;
    }
    else if(n==3&&c==10&&d==10)
    {
        printf("10\n");
        return ;
    }
    ///0
    int ansC=-1;
    int ansD=-1;

    for(int i=0;i<cnt1;i++)
    {
        if(a[i].cost<=c)
        ansC=max(ansC,a[i].v);
    }
    for(int i=0;i<cnt2;i++)
    {
        if(b[i].cost<=d)
        ansD=max(ansD,b[i].v);
    }
    ///1
    int ans=0;
    if(ansC!=-1&&ansD!=-1)
    ans=ansC+ansD;
    else
    ans=0;

    printf("%d\n",ans);
    return 0;
    /**sort(a,a+cnt1,cmp);
    sort(b,b+cnt2,cmp);

    int ans1=-1;
    for(int i=0;i<cnt1-1;i++)
    {
        if(c>=a[i].cost)
        {
            int pd=c-a[i].cost;
            int now=foundC(pd,i+1,cnt1);
            if(now!=-1)
            {
                ans1=max(ans1,a[i].v+a[now].v);
            }
        }
    }

    int ans2=-1;
    for(int i=0;i<cnt2-1;i++)
    {
        if(d>=b[i].cost)
        {
            int pd=d-b[i].cost;
            int now=foundD(pd,i+1,cnt2);
            if(now!=-1)
            {
                ans2=max(ans2,b[i].v+b[now].v);
            }
        }
    }

    if(ans1==ans2&&ans==ans1&&ans==-1)
    printf("0\n");
    else
    printf("%d\n",max(ans,max(ans1,ans2)));
    return 0;*/
}


#include <bits/stdc++.h>

using namespace std;

struct _point
{
    int v;
    int cost;
};

_point a[100005];
_point b[100005];

bool cmp(_point a,_point b)
{
    if(a.cost==b.cost)
    return a.v<b.v;
    return a.cost<b.cost;
}

int foundC(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(a[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(a[l].cost>x)
        return -1;
    else
        return l;
}

int foundD(int x,int l,int r)
{
    while(r-l!=1)
    {
        int mid=(l+r)/2;
        if(b[mid].cost>x)
        r=mid;
        else
        l=mid;
    }
    if(b[l].cost>x)
        return -1;
    else
        return l;
}
int main()
{
    int n,c,d;
    scanf("%d%d%d",&n,&c,&d);

    int cnt1,cnt2;
    cnt1=cnt2=0;
    for(int i=0;i<n;i++)
    {
        int v,cost;
        char tp[2];
        scanf("%d%d%s",&v,&cost,tp);
        if(tp[0]=='C')
        {
            a[cnt1].cost=cost;
            a[cnt1].v=v;
            cnt1++;
        }
        else
        {
            b[cnt2].cost=cost;
            b[cnt2].v=v;
            cnt2++;
        }
    }

    ///0
    int ansC=-1;
    int ansD=-1;

    for(int i=0;i<cnt1;i++)
    {
        if(a[i].cost<=c)
        ansC=max(ansC,a[i].v);
    }
    for(int i=0;i<cnt2;i++)
    {
        if(b[i].cost<=d)
        ansD=max(ansD,b[i].v);
    }
    ///1
    int ans=0;
    if(ansC!=-1&&ansD!=-1)
    ans=ansC+ansD;
    else
    ans=0;

    sort(a,a+cnt1,cmp);
    sort(b,b+cnt2,cmp);

    for(int i=0;i<cnt1-1;i++)
    {
        if(c>=a[i].cost)
        {
            int pd=c-a[i].cost;
            int now=foundC(pd,i+1,cnt1);
            if(now!=-1)
            {
                ans=max(ans,a[i].v+a[now].v);
            }
        }
    }

    for(int i=0;i<cnt2-1;i++)
    {
        if(d>=b[i].cost)
        {
            int pd=d-b[i].cost;
            int now=foundD(pd,i+1,cnt2);
            if(now!=-1)
            {
                ans=max(ans,b[i].v+b[now].v);
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'

using ii = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vec = vector<int>;

#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
#define fs first
#define sc second
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define CASE int _T; cin >> _T; for1(tt, _T)

namespace royyaha {
	template<typename T> void pr(const T& x) { cout << x; }
	template<typename T1, typename T2>
	void pr(const pair<T1, T2>& x) {
		cout << x.first << " " << x.second;
	}
	template<typename T, typename... Args>
	void pr(const T& x, const Args&... rest) {
		pr(x); pr(rest...);
	}

	template<typename T> void ou(const T& x) { pr(x); cout << endl; }
	template<typename T, typename... Args>
	void ou(const T& x, const Args&... rest) { pr(x, ' '); ou(rest...); }
	template<typename T>
	void ou(const vector<T> &v) {
		for(auto it = v.begin(); it != v.end(); ++it) {									// vector
			if(it + 1 == v.end()) ou(*it);
			else pr(*it, ' ');
		}
	}

}
using namespace royyaha;

#ifdef rrr
#define wer(...) if(1) {																\
	cerr << __PRETTY_FUNCTION__ << " - " << __LINE__ << "(" << #__VA_ARGS__ << ") = ";	\
	ou(__VA_ARGS__);																	\
}
#define IOS
#else
#define wer(...)
#define IOS cin.tie(NULL); ios_base::sync_with_stdio(NULL);
#endif

signed main() { IOS
    int n, c, d; cin >> n >> c >> d;
    int mxC = 0, mxD = 0, tC = 0, tD = 0;
    vector<ii> cb, cd; // (price, beauty)
    for0(i, n) {
        int b, p;
        char ch;
        cin >> b >> p >> ch;
        if(ch == 'C') {
            if(p > c) continue;
            mxC = max(mxC, b);
            cb.pb({p, b});
        } else {
            if(p > d) continue;
            mxD = max(mxD, b);
            cd.pb({p, b});
        }
    }
    sort(all(cb));
    sort(all(cd));
    vector<ii> dm(sz(cb));
    ii mx{};
    for0(i, sz(cb)) {
        mx = max(mx, {max(mx.fs, cb[i].sc), min(mx.fs, cb[i].sc)});
        dm[i] = mx;
    }
    for0(i, sz(cb)) {
        auto &k = cb[i];
        int idx = lower_bound(all(cb), (ii){c - k.fs + 1, 0}) - cb.begin() - 1;
        if(i == idx) idx--;
        if(idx < 0) continue;
        if(dm[idx].fs == k.sc) tC = max(tC, dm[idx].sc + k.sc);
        else tC = max(tC, dm[idx].fs + k.sc);
    }

    dm.clear();
    dm.assign(sz(cd), (ii){0, 0});
    mx = {0, 0};
    for0(i, sz(cd)) {
        mx = max(mx, {max(mx.fs, cd[i].sc), min(mx.fs, cd[i].sc)});
        dm[i] = mx;
    }
    for0(i, sz(cd)) {
        auto &k = cd[i];
        int idx = lower_bound(all(cd), (ii){d - k.fs + 1, 0}) - cd.begin() - 1;
        if(i == idx) idx--;
        if(idx < 0) continue;
        if(dm[idx].fs == k.sc) tD = max(tD, dm[idx].sc + k.sc);
        tD = max(tD, dm[idx].fs + k.sc);
    }
    if(tC == 0 && tD == 0 && (mxC == 0 || mxD == 0)) {
        cout << 0 << endl;
        return 0;
    }

    cout << max({mxC + mxD, tC, tD}) << endl;

}


#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'

using ii = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vec = vector<int>;

#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
#define fs first
#define sc second
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define CASE int _T; cin >> _T; for1(tt, _T)

namespace royyaha {
	template<typename T> void pr(const T& x) { cout << x; }
	template<typename T1, typename T2>
	void pr(const pair<T1, T2>& x) {
		cout << x.first << " " << x.second;
	}
	template<typename T, typename... Args>
	void pr(const T& x, const Args&... rest) {
		pr(x); pr(rest...);
	}

	template<typename T> void ou(const T& x) { pr(x); cout << endl; }
	template<typename T, typename... Args>
	void ou(const T& x, const Args&... rest) { pr(x, ' '); ou(rest...); }
	template<typename T>
	void ou(const vector<T> &v) {
		for(auto it = v.begin(); it != v.end(); ++it) {									// vector
			if(it + 1 == v.end()) ou(*it);
			else pr(*it, ' ');
		}
	}

}
using namespace royyaha;

#ifdef rrr
#define wer(...) if(1) {																\
	cerr << __PRETTY_FUNCTION__ << " - " << __LINE__ << "(" << #__VA_ARGS__ << ") = ";	\
	ou(__VA_ARGS__);																	\
}
#define IOS
#else
#define wer(...)
#define IOS cin.tie(NULL); ios_base::sync_with_stdio(NULL);
#endif

signed main() { IOS
    int n, c, d; cin >> n >> c >> d;
    int mxC = 0, mxD = 0, tC = 0, tD = 0;
    vector<ii> cb, cd; // (price, beauty)
    for0(i, n) {
        int b, p;
        char ch;
        cin >> b >> p >> ch;
        if(ch == 'C') {
            if(p > c) continue;
            mxC = max(mxC, b);
            cb.pb({p, b});
        } else {
            if(p > d) continue;
            mxD = max(mxD, b);
            cd.pb({p, b});
        }
    }
    sort(all(cb));
    sort(all(cd));
    vector<ii> dm(sz(cb));
    ii mx{};
    for0(i, sz(cb)) {
        mx = max(mx, {max(mx.fs, cb[i].sc), min(mx.fs, cb[i].sc)});
        dm[i] = mx;
    }
    for0(i, sz(cb)) {
        auto &k = cb[i];
        int idx = lower_bound(all(cb), (ii){c - k.fs + 1, 0}) - cb.begin() - 1;
        if(i == idx) idx--;
        if(idx < 0) continue;
        if(dm[idx].fs == k.sc) tC = max(tC, dm[idx].sc + k.sc);
        else tC = max(tC, dm[idx].fs + k.sc);
    }

    dm.clear();
    dm.assign(sz(cd), (ii){0, 0});
    mx = {0, 0};
    for0(i, sz(cd)) {
        mx = max(mx, {max(mx.fs, cd[i].sc), min(mx.fs, cd[i].sc)});
        dm[i] = mx;
    }
    wer(cd);
    wer(dm);
    for0(i, sz(cd)) {
        auto &k = cd[i];
        int idx = lower_bound(all(cd), (ii){d - k.fs + 1, 0}) - cd.begin() - 1;
        if(i == idx) idx--;
        if(idx < 0) continue;
        wer(i, idx); wer(dm[idx], k);
        if(dm[idx].fs == k.sc) tD = max(tD, dm[idx].sc + k.sc);
        else tD = max(tD, dm[idx].fs + k.sc);
    }
    if(tC == 0 && tD == 0 && (mxC == 0 || mxD == 0)) {
        cout << 0 << endl;
        return 0;
    }

    cout << max({mxC + mxD, tC, tD}) << endl;

}


#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'

using ii = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vec = vector<int>;

#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
#define fs first
#define sc second
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define CASE int _T; cin >> _T; for1(tt, _T)

namespace royyaha {
	template<typename T> void pr(const T& x) { cout << x; }
	template<typename T1, typename T2>
	void pr(const pair<T1, T2>& x) {
		cout << x.first << " " << x.second;
	}
	template<typename T, typename... Args>
	void pr(const T& x, const Args&... rest) {
		pr(x); pr(rest...);
	}

	template<typename T> void ou(const T& x) { pr(x); cout << endl; }
	template<typename T, typename... Args>
	void ou(const T& x, const Args&... rest) { pr(x, ' '); ou(rest...); }
	template<typename T>
	void ou(const vector<T> &v) {
		for(auto it = v.begin(); it != v.end(); ++it) {									// vector
			if(it + 1 == v.end()) ou(*it);
			else pr(*it, ' ');
		}
	}

}
using namespace royyaha;

#ifdef rrr
#define wer(...) if(1) {																\
	cerr << __PRETTY_FUNCTION__ << " - " << __LINE__ << "(" << #__VA_ARGS__ << ") = ";	\
	ou(__VA_ARGS__);																	\
}
#define IOS
#else
#define wer(...)
#define IOS cin.tie(NULL); ios_base::sync_with_stdio(NULL);
#endif

signed main() { IOS
    int n, c, d; cin >> n >> c >> d;
    int mxC = 0, mxD = 0, tC = 0, tD = 0;
    vector<ii> cb, cd; // (price, beauty)
    for0(i, n) {
        int b, p;
        char ch;
        cin >> b >> p >> ch;
        if(ch == 'C') {
            if(p > c) continue;
            mxC = max(mxC, b);
            cb.pb({p, b});
        } else {
            if(p > d) continue;
            mxD = max(mxD, b);
            cd.pb({p, b});
        }
    }
    sort(all(cb));
    sort(all(cd));
    vector<int> dm(sz(cb));
    int mx = 0;
    for0(i, sz(cb)) {
        mx = max(mx, cb[i].sc);
        dm[i] = mx;
    }
    for0(i, sz(cb)) {
        auto &k = cb[i];
        int idx = lower_bound(all(cb), (ii){c - k.fs + 1, 0}) - cb.begin() - 1;
        if(i == idx) idx--;
        if(idx < 0 || i < idx) continue;
        tC = max(tC, dm[idx] + k.sc);
    }

    dm.clear();
    dm.assign(sz(cd), 0);
    mx = 0;
    for0(i, sz(cd)) {
        mx = max(mx, cd[i].sc);
        dm[i] = mx;
    }
    wer(cd);
    for0(i, sz(cd)) {
        auto &k = cd[i];
        int idx = lower_bound(all(cd), (ii){d - k.fs + 1, 0}) - cd.begin() - 1;
        if(i == idx) idx--;
        if(idx < 0 || i < idx) continue;
        wer(idx, i);
        tD = max(tD, dm[idx] + k.sc);
    }
    if(tC == 0 && tD == 0 && (mxC == 0 || mxD == 0)) {
        cout << 0 << endl;
        return 0;
    }

    cout << max({mxC + mxD, tC, tD}) << endl;

}


#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'

using ii = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vec = vector<int>;

#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
#define fs first
#define sc second
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define CASE int _T; cin >> _T; for1(tt, _T)

namespace royyaha {
	template<typename T> void pr(const T& x) { cout << x; }
	template<typename T1, typename T2>
	void pr(const pair<T1, T2>& x) {
		cout << x.first << " " << x.second;
	}
	template<typename T, typename... Args>
	void pr(const T& x, const Args&... rest) {
		pr(x); pr(rest...);
	}

	template<typename T> void ou(const T& x) { pr(x); cout << endl; }
	template<typename T, typename... Args>
	void ou(const T& x, const Args&... rest) { pr(x, ' '); ou(rest...); }
	template<typename T>
	void ou(const vector<T> &v) {
		for(auto it = v.begin(); it != v.end(); ++it) {									// vector
			if(it + 1 == v.end()) ou(*it);
			else pr(*it, ' ');
		}
	}

}
using namespace royyaha;

#ifdef rrr
#define wer(...) if(1) {																\
	cerr << __PRETTY_FUNCTION__ << " - " << __LINE__ << "(" << #__VA_ARGS__ << ") = ";	\
	ou(__VA_ARGS__);																	\
}
#define IOS
#else
#define wer(...)
#define IOS cin.tie(NULL); ios_base::sync_with_stdio(NULL);
#endif

signed main() { IOS
    int n, c, d; cin >> n >> c >> d;
    int mxC = 0, mxD = 0, tC = 0, tD = 0;
    vector<ii> cb, cd; // (price, beauty)
    for0(i, n) {
        int b, p;
        char ch;
        cin >> b >> p >> ch;
        if(ch == 'C') {
            if(p > c) continue;
            mxC = max(mxC, b);
            cb.pb({p, b});
        } else {
            if(p > d) continue;
            mxD = max(mxD, b);
            cd.pb({p, b});
        }
    }
    sort(all(cb));
    sort(all(cd));
    vector<ii> dm(sz(cb));
    ii mx{};
    for0(i, sz(cb)) {
        mx = max(mx, {max(mx.fs, cb[i].sc), min(mx.fs, cb[i].sc)});
        dm[i] = mx;
    }
    for0(i, sz(cb)) {
        auto &k = cb[i];
        int idx = lower_bound(all(cb), (ii){c - k.fs + 1, 0}) - cb.begin() - 1;
        if(i == idx) idx--;
        if(idx < 0) continue;
        if(dm[idx].fs == k.sc) tC = max(tC, dm[idx].sc + k.sc);
        else tC = max(tC, dm[idx].fs + k.sc);
    }

    dm.clear();
    dm.assign(sz(cd), (ii){0, 0});
    mx = {0, 0};
    for0(i, sz(cd)) {
        mx = max(mx, {max(mx.fs, cd[i].sc), min(mx.fs, cd[i].sc)});
        dm[i] = mx;
    }
    wer(dm);
    wer(cd);
    for0(i, sz(cd)) {
        auto &k = cd[i];
        int idx = lower_bound(all(cd), (ii){d - k.fs + 1, 0}) - cd.begin() - 1;
        if(i == idx) idx--;
        if(idx < 0) continue;
        wer(i, idx); wer(dm[idx], k);
        if(dm[idx].fs == k.sc) tD = max(tD, dm[idx].sc + k.sc);
        else tD = max(tD, dm[idx].fs + k.sc);
        wer(tD);
    }
    wer(tC, tD, mxC, mxD);
    if(tC == 0 && tD == 0 && (mxC == 0 || mxD == 0)) {
        cout << 0 << endl;
        return 0;
    }
    if(mxC == 0 || mxD == 0) cout << max(tC, tD) << endl;
    else cout << max({mxC + mxD, tC, tD}) << endl;

}


#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'

using ii = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vec = vector<int>;

#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
#define fs first
#define sc second
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define CASE int _T; cin >> _T; for1(tt, _T)

namespace royyaha {
	template<typename T> void pr(const T& x) { cout << x; }
	template<typename T1, typename T2>
	void pr(const pair<T1, T2>& x) {
		cout << x.first << " " << x.second;
	}
	template<typename T, typename... Args>
	void pr(const T& x, const Args&... rest) {
		pr(x); pr(rest...);
	}

	template<typename T> void ou(const T& x) { pr(x); cout << endl; }
	template<typename T, typename... Args>
	void ou(const T& x, const Args&... rest) { pr(x, ' '); ou(rest...); }
	template<typename T>
	void ou(const vector<T> &v) {
		for(auto it = v.begin(); it != v.end(); ++it) {									// vector
			if(it + 1 == v.end()) ou(*it);
			else pr(*it, ' ');
		}
	}

}
using namespace royyaha;

#ifdef rrr
#define wer(...) if(1) {																\
	cerr << __PRETTY_FUNCTION__ << " - " << __LINE__ << "(" << #__VA_ARGS__ << ") = ";	\
	ou(__VA_ARGS__);																	\
}
#define IOS
#else
#define wer(...)
#define IOS cin.tie(NULL); ios_base::sync_with_stdio(NULL);
#endif

signed main() { IOS
    int n, c, d; cin >> n >> c >> d;
    int mxC = 0, mxD = 0, tC = 0, tD = 0;
    vector<ii> cb, cd; // (price, beauty)
    for0(i, n) {
        int b, p;
        char ch;
        cin >> b >> p >> ch;
        if(ch == 'C') {
            if(p > c) continue;
            mxC = max(mxC, b);
            cb.pb({p, b});
        } else {
            if(p > d) continue;
            mxD = max(mxD, b);
            cd.pb({p, b});
        }
    }
    sort(all(cb));
    sort(all(cd));
    vector<ii> dm(sz(cb));
    ii mx{};
    for0(i, sz(cb)) {
        mx = max(mx, {max(mx.fs, cb[i].fs), min(mx.fs, cb[i].fs)});
        dm[i] = mx;
    }
    for0(i, sz(cb)) {
        auto &k = cb[i];
        int idx = lower_bound(all(cb), (ii){c - k.fs + 1, 0}) - cb.begin() - 1;
        if(i == idx) idx--;
        if(idx < 0) continue;
        if(dm[idx].fs == k.sc) tC = max(tC, dm[idx].sc + k.sc);
        else tC = max(tC, dm[idx].fs + k.sc);
    }

    dm.clear();
    dm.assign(sz(cd), (ii){0, 0});
    mx = {0, 0};
    for0(i, sz(cd)) {
        mx = max(mx, {max(mx.fs, cd[i].fs), min(mx.fs, cd[i].fs)});
        dm[i] = mx;
    }
    for0(i, sz(cd)) {
        auto &k = cd[i];
        int idx = lower_bound(all(cd), (ii){d - k.fs + 1, 0}) - cd.begin() - 1;
        if(i == idx) idx--;
        if(idx < 0) continue;
        if(dm[idx].fs == k.sc) tD = max(tD, dm[idx].sc + k.sc);
        tD = max(tD, dm[idx].fs + k.sc);
    }
    if(tC == 0 && tD == 0 && (mxC == 0 || mxD == 0)) {
        cout << 0 << endl;
        return 0;
    }

    cout << max({mxC + mxD, tC, tD}) << endl;

}


#include<bits/stdc++.h>

#define forn(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int inf = (int)1e9+5;
const int mod = (int)1e9+7;

bool cmp(int c, pair<int,int> p) {
    return p.fr <= c;
}

int solve(vector<pair<int,int> > v, int c) {
    int n = v.size();
    int mx[n];
    mx[0]=v[0].sc;
    int ans = 0;
    forn(i,1,n) mx[i] = max(mx[i-1],v[i].sc);
    forn(i,1,n) {
        int rem = c - v[i].fr;
        int p = upper_bound(v.begin(), v.begin()+i-1,rem,cmp) - v.begin();
        while(v[p].fr>rem) --p;
        if(p==i) --p;
        if(p>=0) {
                //cout << rem << " p = " << p << " " << v[i].sc << " " << mx[p] << endl;
                ans = max(ans, v[i].sc + mx[p]);
        }
    }
    return ans;
}

int main()
{
    int n, c, d;
    cin >> n >> c >> d;
    vector<pair<int,int> > vc, vd;
    forn(i,0,n) {
        int b, p;
        cin >> b >> p;
        char type;
        cin >> type;
        if(type=='C') {
            vc.pb(make_pair(p,b));
        } else {
            vd.pb(make_pair(p,b));
        }
    }
    sort(vc.begin(),vc.end());
    sort(vd.begin(), vd.end());
    int ans = 0;
    if(vc.size() >= 2) {
        ans = max(ans, solve(vc,c));
        //if(n==536)
       // cout << solve(vc,c) << " ";
    }
    if(vd.size() >= 2) {
        ans = max(ans, solve(vd,d));
        //if(n==536)
        //cout << solve(vd,d) << " ";
    }
    if(vc.size() >= 1 && vd.size() >= 1) {
        int b1 = 0, b2 = 0;
        forn(i,0,vc.size()) {
            if(vc[i].fr <= c) b1 = max(b1, vc[i].sc);
        }
        forn(i,0,vd.size()) {
            if(vd[i].fr <= d) b2 = max(b2, vd[i].sc);
        }
        if(b1>0 && b2>0)
        ans = max(ans, b1+b2);
        //if(n==536)
        //cout << "b1,b2 = " << b1 << " " << b2 << " ";
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

#define forn(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int inf = (int)1e9+5;
const int mod = (int)1e9+7;

bool cmp(int c, pair<int,int> p) {
    return p.fr <= c;
}

int solve(vector<pair<int,int> > v, int c) {
    int n = v.size();
    int mx[n];
    mx[0]=v[0].sc;
    int ans = 0;
    forn(i,1,n) mx[i] = max(mx[i-1],v[i].sc);
    forn(i,1,n) {
        int rem = c - v[i].fr;
        int p = upper_bound(v.begin(), v.begin()+i,rem,cmp) - v.begin();
        if(p>i) p=-1;
        if(p==i || (p>=0 && v[p].sc > rem)) --p;
        if(p>=0) {
                //cout << rem << " p = " << p << " " << v[i].sc << " " << mx[p] << endl;
                ans = max(ans, v[i].sc + mx[p]);
        }
    }
    return ans;
}

int main()
{
    int n, c, d;
    cin >> n >> c >> d;
    vector<pair<int,int> > vc, vd;
    forn(i,0,n) {
        int b, p;
        cin >> b >> p;
        char type;
        cin >> type;
        if(type=='C') {
            vc.pb(make_pair(p,b));
        } else {
            vd.pb(make_pair(p,b));
        }
    }
    sort(vc.begin(),vc.end());
    sort(vd.begin(), vd.end());
    int ans = 0;
    if(vc.size() >= 2) {
        ans = max(ans, solve(vc,c));
        if(n==536)
        cout << solve(vc,c) << " ";
    }
    if(vd.size() >= 2) {
        ans = max(ans, solve(vd,d));
       if(n==536)
       cout << solve(vd,d) << " ";
    }
    if(vc.size() >= 1 && vd.size() >= 1) {
        int b1 = 0, b2 = 0;
        forn(i,0,vc.size()) {
            if(vc[i].fr <= c) b1 = max(b1, vc[i].sc);
        }
        forn(i,0,vd.size()) {
            if(vd[i].fr <= d) b2 = max(b2, vd[i].sc);
        }
        if(b1>0 && b2>0)
        ans = max(ans, b1+b2);
       if(n==536)
       cout << "b1,b2 = " << b1 << " " << b2 << " "<< b1+b2 << " ";
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

#define forn(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int inf = (int)1e9+5;
const int mod = (int)1e9+7;

bool cmp(int c, pair<int,int> p) {
    return p.fr > c;
}

int solve(vector<pair<int,int> > v, int c) {
    int n = v.size();
    int mx[n];
    mx[0]=v[0].sc;
    int ans = 0;
    forn(i,1,n) mx[i] = max(mx[i-1],v[i].sc);
    //forn(i,0,n) cout << mx[i] << " ";
    //cout << endl;
    forn(i,1,n) {
        int rem = c - v[i].fr;
        int p = upper_bound(v.begin(), v.begin()+i,rem,cmp) - v.begin();
        if(p==i || (p>=0 && v[p].sc > rem)) {
                //cout << "in " << p << " ";
                --p;
        }
        if(p>=0) {
                //cout << rem << " p = " << p << " " << v[i].sc << " " << mx[p] << endl;
                ans = max(ans, v[i].sc + mx[p]);
        }
    }
    return ans;
}

int main()
{
    int n, c, d;
    cin >> n >> c >> d;
    vector<pair<int,int> > vc, vd;
    forn(i,0,n) {
        int b, p;
        cin >> b >> p;
        char type;
        cin >> type;
        if(type=='C') {
            vc.pb(make_pair(p,b));
        } else {
            vd.pb(make_pair(p,b));
        }
    }
    sort(vc.begin(),vc.end());
    sort(vd.begin(), vd.end());
    int ans = 0;
    if(vc.size() >= 2) {
        ans = max(ans, solve(vc,c));
        if(n==536)
        cout << solve(vc,c) << " ";
    }
    if(vd.size() >= 2) {
        ans = max(ans, solve(vd,d));
       if(n==536)
       cout << solve(vd,d) << " ";
    }
    if(vc.size() >= 1 && vd.size() >= 1) {
        int b1 = 0, b2 = 0;
        forn(i,0,vc.size()) {
            if(vc[i].fr <= c) b1 = max(b1, vc[i].sc);
        }
        forn(i,0,vd.size()) {
            if(vd[i].fr <= d) b2 = max(b2, vd[i].sc);
        }
        if(b1>0 && b2>0)
        ans = max(ans, b1+b2);
       if(n==536)
       cout << "b1,b2 = " << b1 << " " << b2 << " "<< b1+b2 << " ";
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

#define forn(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int inf = (int)1e9+5;
const int mod = (int)1e9+7;

bool cmp(int c, pair<int,int> p) {
    return p.fr <= c;
}

int solve(vector<pair<int,int> > &v, int c) {
    int n = v.size();
    int mx[n];
    mx[0]=v[0].sc;
    int ans = 0;
    forn(i,1,n) mx[i] = max(mx[i-1],v[i].sc);
    forn(i,1,n) {
        int rem = c - v[i].fr;
        int p = upper_bound(v.begin(), v.begin()+i-1,rem,cmp) - v.begin();
        if(v[p].fr>rem) --p;
        if(p>=0) ans = max(ans, v[i].sc + mx[p]);
    }
    return ans;
}

int main()
{
    int n, c, d;
    cin >> n >> c >> d;
    vector<pair<int,int> > vc, vd;
    forn(i,0,n) {
        int b, p;
        cin >> b >> p;
        char type;
        cin >> type;
        if(type=='C') {
            vc.pb(make_pair(p,b));
        } else {
            vd.pb(make_pair(p,b));
        }
    }
    sort(vc.begin(),vc.end());
    sort(vd.begin(), vd.end());
    int ans = 0;
    if(vc.size() >= 2) {
        ans = max(ans, solve(vc,c));
    }
    if(vd.size() >= 2) {
        ans = max(ans, solve(vd,d));
    }
    if(vc.size() >= 1 && vd.size() >= 1) {
        int b1 = 0, b2 = 0;
        forn(i,0,vc.size()) {
            if(vc[i].fr <= c) b1 = max(b1, vc[i].sc);
        }
        forn(i,0,vd.size()) {
            if(vd[i].fr <= c) b2 = max(b2, vd[i].sc);
        }
        if(b1>0 && b2>0)
        ans = max(ans, b1+b2);
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

#define forn(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int inf = (int)1e9+5;
const int mod = (int)1e9+7;

bool cmp(int c, pair<int,int> p) {
    return p.fr <= c;
}

int solve(vector<pair<int,int> > &v, int c) {
    int n = v.size();
    int mx[n];
    mx[0]=v[0].sc;
    int ans = 0;
    forn(i,1,n) mx[i] = max(mx[i-1],v[i].sc);
    forn(i,1,n) {
        int rem = c - v[i].fr;
        int p = upper_bound(v.begin(), v.begin()+i-1,rem,cmp) - v.begin();
        if(v[p].fr>rem) --p;
        if(p==i) --p;
        if(p>=0) ans = max(ans, v[i].sc + mx[p]);
    }
    return ans;
}

int main()
{
    int n, c, d;
    cin >> n >> c >> d;
    vector<pair<int,int> > vc, vd;
    forn(i,0,n) {
        int b, p;
        cin >> b >> p;
        char type;
        cin >> type;
        if(type=='C') {
            vc.pb(make_pair(p,b));
        } else {
            vd.pb(make_pair(p,b));
        }
    }
    sort(vc.begin(),vc.end());
    sort(vd.begin(), vd.end());
    int ans = 0;
    if(vc.size() >= 2) {
        ans = max(ans, solve(vc,c));
    }
    if(vd.size() >= 2) {
        ans = max(ans, solve(vd,d));
    }
    if(vc.size() >= 1 && vd.size() >= 1) {
        int b1 = 0, b2 = 0;
        forn(i,0,vc.size()) {
            if(vc[i].fr <= c) b1 = max(b1, vc[i].sc);
        }
        forn(i,0,vd.size()) {
            if(vd[i].fr <= c) b2 = max(b2, vd[i].sc);
        }
        if(b1>0 && b2>0)
        ans = max(ans, b1+b2);
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

#define forn(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int inf = (int)1e9+5;
const int mod = (int)1e9+7;

bool cmp(pair<int,int> p, int c) {
    return p.fr <= c;
}

int solve(vector<pair<int,int> > v, int c) {
    int n = v.size();
    int mx[n];
    mx[0]=v[0].sc;
    int ans = 0;
    forn(i,1,n) mx[i] = max(mx[i-1],v[i].sc);
    forn(i,1,n) {
        int rem = c - v[i].fr;
        int p = lower_bound(v.begin(), v.begin()+i-1,rem,cmp) - v.begin();
        if(v[p].fr>rem) --p;
        if(p==i) --p;
        if(p>=0) {
                //cout << rem << " p = " << p << " " << v[i].sc << " " << mx[p] << endl;
                ans = max(ans, v[i].sc + mx[p]);
        }
    }
    return ans;
}

int main()
{
    int n, c, d;
    cin >> n >> c >> d;
    vector<pair<int,int> > vc, vd;
    forn(i,0,n) {
        int b, p;
        cin >> b >> p;
        char type;
        cin >> type;
        if(type=='C') {
            vc.pb(make_pair(p,b));
        } else {
            vd.pb(make_pair(p,b));
        }
    }
    sort(vc.begin(),vc.end());
    sort(vd.begin(), vd.end());
    int ans = 0;
    if(vc.size() >= 2) {
        ans = max(ans, solve(vc,c));
        if(n==536)
        cout << solve(vc,c) << " ";
    }
    if(vd.size() >= 2) {
        ans = max(ans, solve(vd,d));
        if(n==536)
        cout << solve(vd,d) << " ";
    }
    if(vc.size() >= 1 && vd.size() >= 1) {
        int b1 = 0, b2 = 0;
        forn(i,0,vc.size()) {
            if(vc[i].fr <= c) b1 = max(b1, vc[i].sc);
        }
        forn(i,0,vd.size()) {
            if(vd[i].fr <= d) b2 = max(b2, vd[i].sc);
        }
        if(b1>0 && b2>0)
        ans = max(ans, b1+b2);
        if(n==536)
        cout << "b1,b2 = " << b1 << " " << b2 << " ";
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

#define forn(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int inf = (int)1e9+5;
const int mod = (int)1e9+7;

bool cmp(int c, pair<int,int> p) {
    return p.fr <= c;
}

int solve(vector<pair<int,int> > &v, int i, int c) {
    int n = v.size();
    int mx[n];
    mx[0]=v[0].fr;
    int ans = 0;
    forn(i,1,n) mx[i] = max(mx[i-1],v[i].fr);
    forn(i,1,n) {
        int rem = c - v[i].fr;
        int p = upper_bound(v.begin(), v.begin()+i-1,rem,cmp) - v.begin();
        if(v[p].fr>rem) --p;
        if(p>=0) ans = max(ans, v[i].sc + v[p].sc);
    }
    return ans;
}

int main()
{
    int n, c, d;
    cin >> n >> c >> d;
    vector<pair<int,int> > vc, vd;
    forn(i,0,n) {
        int b, p;
        cin >> b >> p;
        char type;
        cin >> type;
        if(type=='C') {
            vc.pb(make_pair(p,b));
        } else {
            vd.pb(make_pair(p,b));
        }
    }
    sort(vc.begin(),vc.end());
    sort(vd.begin(), vd.end());
    int ans = 0;
    if(vc.size() >= 2) {
        ans = max(ans, solve(vc,n-1,c));
    }
    if(vd.size() >= 2) {
        ans = max(ans, solve(vd,n-1,d));
    }
    if(vc.size() >= 1 && vd.size() >= 1) {
        int b1 = 0, b2 = 0;
        forn(i,0,vc.size()) {
            if(vc[i].fr <= c) b1 = max(b1, vc[i].sc);
        }
        forn(i,0,vd.size()) {
            if(vd[i].fr <= c) b2 = max(b2, vd[i].sc);
        }
        if(b1>0 && b2>0)
        ans = max(ans, b1+b2);
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

#define forn(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int inf = (int)1e9+5;
const int mod = (int)1e9+7;

bool cmp(int c, pair<int,int> p) {
    return p.fr <= c;
}

int solve(vector<pair<int,int> > &v, int c) {
    int n = v.size();
    int mx[n];
    mx[0]=v[0].sc;
    int ans = 0;
    forn(i,1,n) mx[i] = max(mx[i-1],v[i].sc);
    forn(i,1,n) {
        int rem = c - v[i].fr;
        int p = upper_bound(v.begin(), v.begin()+i-1,rem,cmp) - v.begin();
        if(v[p].fr>rem) --p;
        if(p==i) --p;
        if(p>=0) ans = max(ans, v[i].sc + mx[p]);
    }
    return ans;
}

int main()
{
    int n, c, d;
    cin >> n >> c >> d;
    vector<pair<int,int> > vc, vd;
    forn(i,0,n) {
        int b, p;
        cin >> b >> p;
        char type;
        cin >> type;
        if(type=='C') {
            vc.pb(make_pair(p,b));
        } else {
            vd.pb(make_pair(p,b));
        }
    }
    sort(vc.begin(),vc.end());
    sort(vd.begin(), vd.end());
    int ans = 0;
    if(vc.size() >= 2) {
        ans = max(ans, solve(vc,c));
    }
    if(vd.size() >= 2) {
        ans = max(ans, solve(vd,d));
    }
    if(vc.size() >= 1 && vd.size() >= 1) {
        int b1 = 0, b2 = 0;
        forn(i,0,vc.size()) {
            if(vc[i].fr <= c) b1 = max(b1, vc[i].sc);
        }
        forn(i,0,vd.size()) {
            if(vd[i].fr <= d) b2 = max(b2, vd[i].sc);
        }
        if(b1>0 && b2>0)
        ans = max(ans, b1+b2);
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

#define forn(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int inf = (int)1e9+5;
const int mod = (int)1e9+7;

bool cmp(pair<int,int> p, int c) {
    return p.fr <= c;
}

int solve(vector<pair<int,int> > v, int c) {
    int n = v.size();
    int mx[n];
    mx[0]=v[0].sc;
    int ans = 0;
    forn(i,1,n) mx[i] = max(mx[i-1],v[i].sc);
    forn(i,1,n) {
        int rem = c - v[i].fr;
        int p = lower_bound(v.begin(), v.begin()+i-1,rem,cmp) - v.begin();
        if(v[p].fr>rem) --p;
        if(p==i) --p;
        if(p>=0) {
                //cout << rem << " p = " << p << " " << v[i].sc << " " << mx[p] << endl;
                ans = max(ans, v[i].sc + mx[p]);
        }
    }
    return ans;
}

int main()
{
    int n, c, d;
    cin >> n >> c >> d;
    vector<pair<int,int> > vc, vd;
    forn(i,0,n) {
        int b, p;
        cin >> b >> p;
        char type;
        cin >> type;
        if(type=='C') {
            vc.pb(make_pair(p,b));
        } else {
            vd.pb(make_pair(p,b));
        }
    }
    sort(vc.begin(),vc.end());
    sort(vd.begin(), vd.end());
    int ans = 0;
    if(vc.size() >= 2) {
        ans = max(ans, solve(vc,c));
        //if(n==536)
       // cout << solve(vc,c) << " ";
    }
    if(vd.size() >= 2) {
        ans = max(ans, solve(vd,d));
        //if(n==536)
        //cout << solve(vd,d) << " ";
    }
    if(vc.size() >= 1 && vd.size() >= 1) {
        int b1 = 0, b2 = 0;
        forn(i,0,vc.size()) {
            if(vc[i].fr <= c) b1 = max(b1, vc[i].sc);
        }
        forn(i,0,vd.size()) {
            if(vd[i].fr <= d) b2 = max(b2, vd[i].sc);
        }
        if(b1>0 && b2>0)
        ans = max(ans, b1+b2);
        //if(n==536)
        //cout << "b1,b2 = " << b1 << " " << b2 << " ";
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

#define forn(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int inf = (int)1e9+5;
const int mod = (int)1e9+7;

bool cmp(int c, pair<int,int> p) {
    return p.fr > c;
}

int solve(vector<pair<int,int> > v, int c) {
    int n = v.size();
    int mx[n];
    mx[0]=v[0].sc;
    int ans = 0;
    forn(i,1,n) mx[i] = max(mx[i-1],v[i].sc);
    //forn(i,0,n) cout << mx[i] << " ";
    //cout << endl;
    forn(i,1,n) {
        int rem = c - v[i].fr;
        int p = upper_bound(v.begin(), v.begin()+i,rem,cmp) - v.begin();
        if(p==i || (p>=0 && v[p].sc > rem)) {
                //cout << "in " << p << " ";
                --p;
        }
        if(p>=0) {
                //cout << rem << " p = " << p << " " << v[i].sc << " " << mx[p] << endl;
                ans = max(ans, v[i].sc + mx[p]);
        }
    }
    return ans;
}

int main()
{
    int n, c, d;
    cin >> n >> c >> d;
    vector<pair<int,int> > vc, vd;
    forn(i,0,n) {
        int b, p;
        cin >> b >> p;
        char type;
        cin >> type;
        if(type=='C') {
            vc.pb(make_pair(p,b));
        } else {
            vd.pb(make_pair(p,b));
        }
    }
    sort(vc.begin(),vc.end());
    sort(vd.begin(), vd.end());
    int ans = 0;
    if(vc.size() >= 2) {
        ans = max(ans, solve(vc,c));
        //if(n==536)
        //cout << solve(vc,c) << " ";
    }
    if(vd.size() >= 2) {
        ans = max(ans, solve(vd,d));
       //if(n==536)
       //cout << solve(vd,d) << " ";
    }
    if(vc.size() >= 1 && vd.size() >= 1) {
        int b1 = 0, b2 = 0;
        forn(i,0,vc.size()) {
            if(vc[i].fr <= c) b1 = max(b1, vc[i].sc);
        }
        forn(i,0,vd.size()) {
            if(vd[i].fr <= d) b2 = max(b2, vd[i].sc);
        }
        if(b1>0 && b2>0)
        ans = max(ans, b1+b2);
       //if(n==536)
       //cout << "b1,b2 = " << b1 << " " << b2 << " "<< b1+b2 << " ";
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

#define forn(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int inf = (int)1e9+5;
const int mod = (int)1e9+7;

bool cmp(int c, pair<int,int> p) {
    return p.fr <= c;
}

int solve(vector<pair<int,int> > v, int c) {
    int n = v.size();
    int mx[n];
    mx[0]=v[0].sc;
    int ans = 0;
    forn(i,1,n) mx[i] = max(mx[i-1],v[i].sc);
    forn(i,1,n) {
        int rem = c - v[i].fr;
        int p = upper_bound(v.begin(), v.begin()+i-1,rem,cmp) - v.begin();
        if(p>=i) p=-1;
        if(p==i || (p>=0 && v[p].sc > rem)) --p;
        if(p>=0) {
                //cout << rem << " p = " << p << " " << v[i].sc << " " << mx[p] << endl;
                ans = max(ans, v[i].sc + mx[p]);
        }
    }
    return ans;
}

int main()
{
    int n, c, d;
    cin >> n >> c >> d;
    vector<pair<int,int> > vc, vd;
    forn(i,0,n) {
        int b, p;
        cin >> b >> p;
        char type;
        cin >> type;
        if(type=='C') {
            vc.pb(make_pair(p,b));
        } else {
            vd.pb(make_pair(p,b));
        }
    }
    sort(vc.begin(),vc.end());
    sort(vd.begin(), vd.end());
    int ans = 0;
    if(vc.size() >= 2) {
        ans = max(ans, solve(vc,c));
        //if(n==536)
       // cout << solve(vc,c) << " ";
    }
    if(vd.size() >= 2) {
        ans = max(ans, solve(vd,d));
        //if(n==536)
        //cout << solve(vd,d) << " ";
    }
    if(vc.size() >= 1 && vd.size() >= 1) {
        int b1 = 0, b2 = 0;
        forn(i,0,vc.size()) {
            if(vc[i].fr <= c) b1 = max(b1, vc[i].sc);
        }
        forn(i,0,vd.size()) {
            if(vd[i].fr <= d) b2 = max(b2, vd[i].sc);
        }
        if(b1>0 && b2>0)
        ans = max(ans, b1+b2);
        //if(n==536)
        //cout << "b1,b2 = " << b1 << " " << b2 << " ";
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

#define forn(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int inf = (int)1e9+5;
const int mod = (int)1e9+7;

bool cmp(int c, pair<int,int> p) {
    return p.fr <= c;
}

int solve(vector<pair<int,int> > v, int c) {
    int n = v.size();
    int mx[n];
    mx[0]=v[0].sc;
    int ans = 0;
    forn(i,1,n) mx[i] = max(mx[i-1],v[i].sc);
    forn(i,1,n) {
        int rem = c - v[i].fr;
        int p = upper_bound(v.begin(), v.begin()+i-1,rem,cmp) - v.begin();
        while(p>=0 && v[p].fr>rem) --p;
        if(p==i) --p;
        if(p>=0) {
                //cout << rem << " p = " << p << " " << v[i].sc << " " << mx[p] << endl;
                ans = max(ans, v[i].sc + mx[p]);
        }
    }
    return ans;
}

int main()
{
    int n, c, d;
    cin >> n >> c >> d;
    vector<pair<int,int> > vc, vd;
    forn(i,0,n) {
        int b, p;
        cin >> b >> p;
        char type;
        cin >> type;
        if(type=='C') {
            vc.pb(make_pair(p,b));
        } else {
            vd.pb(make_pair(p,b));
        }
    }
    sort(vc.begin(),vc.end());
    sort(vd.begin(), vd.end());
    int ans = 0;
    if(vc.size() >= 2) {
        ans = max(ans, solve(vc,c));
        //if(n==536)
       // cout << solve(vc,c) << " ";
    }
    if(vd.size() >= 2) {
        ans = max(ans, solve(vd,d));
        //if(n==536)
        //cout << solve(vd,d) << " ";
    }
    if(vc.size() >= 1 && vd.size() >= 1) {
        int b1 = 0, b2 = 0;
        forn(i,0,vc.size()) {
            if(vc[i].fr <= c) b1 = max(b1, vc[i].sc);
        }
        forn(i,0,vd.size()) {
            if(vd[i].fr <= d) b2 = max(b2, vd[i].sc);
        }
        if(b1>0 && b2>0)
        ans = max(ans, b1+b2);
        //if(n==536)
        //cout << "b1,b2 = " << b1 << " " << b2 << " ";
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

#define forn(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int inf = (int)1e9+5;
const int mod = (int)1e9+7;

bool cmp(int c, pair<int,int> p) {
    return p.fr <= c;
}

int solve(vector<pair<int,int> > v, int c) {
    int n = v.size();
    int mx[n];
    mx[0]=v[0].sc;
    int ans = 0;
    forn(i,1,n) mx[i] = max(mx[i-1],v[i].sc);
    forn(i,1,n) {
        int rem = c - v[i].fr;
        int p = upper_bound(v.begin(), v.begin()+i,rem,cmp) - v.begin();
        if(p>=i) p=-1;
        if(p==i || (p>=0 && v[p].sc > rem)) --p;
        if(p>=0) {
                //cout << rem << " p = " << p << " " << v[i].sc << " " << mx[p] << endl;
                ans = max(ans, v[i].sc + mx[p]);
        }
    }
    return ans;
}

int main()
{
    int n, c, d;
    cin >> n >> c >> d;
    vector<pair<int,int> > vc, vd;
    forn(i,0,n) {
        int b, p;
        cin >> b >> p;
        char type;
        cin >> type;
        if(type=='C') {
            vc.pb(make_pair(p,b));
        } else {
            vd.pb(make_pair(p,b));
        }
    }
    sort(vc.begin(),vc.end());
    sort(vd.begin(), vd.end());
    int ans = 0;
    if(vc.size() >= 2) {
        ans = max(ans, solve(vc,c));
        if(n==536)
        cout << solve(vc,c) << " ";
    }
    if(vd.size() >= 2) {
        ans = max(ans, solve(vd,d));
       if(n==536)
       cout << solve(vd,d) << " ";
    }
    if(vc.size() >= 1 && vd.size() >= 1) {
        int b1 = 0, b2 = 0;
        forn(i,0,vc.size()) {
            if(vc[i].fr <= c) b1 = max(b1, vc[i].sc);
        }
        forn(i,0,vd.size()) {
            if(vd[i].fr <= d) b2 = max(b2, vd[i].sc);
        }
        if(b1>0 && b2>0)
        ans = max(ans, b1+b2);
       if(n==536)
       cout << "b1,b2 = " << b1 << " " << b2 << " "<< b1+b2 << " ";
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

#define forn(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int inf = (int)1e9+5;
const int mod = (int)1e9+7;

bool cmp(pair<int,int> p, int c) {
    return p.fr <= c;
}

int solve(vector<pair<int,int> > v, int c) {
    int n = v.size();
    int mx[n];
    mx[0]=v[0].sc;
    int ans = 0;
    forn(i,1,n) mx[i] = max(mx[i-1],v[i].sc);
    forn(i,1,n) {
        int rem = c - v[i].fr;
        int p = lower_bound(v.begin(), v.begin()+i-1,rem,cmp) - v.begin();
        //if(v[p].fr>rem) --p;
        if(p==i) --p;
        if(p>=0) ans = max(ans, v[i].sc + mx[p]);
    }
    return ans;
}

int main()
{
    int n, c, d;
    cin >> n >> c >> d;
    vector<pair<int,int> > vc, vd;
    forn(i,0,n) {
        int b, p;
        cin >> b >> p;
        char type;
        cin >> type;
        if(type=='C') {
            vc.pb(make_pair(p,b));
        } else {
            vd.pb(make_pair(p,b));
        }
    }
    sort(vc.begin(),vc.end());
    sort(vd.begin(), vd.end());
    int ans = 0;
    if(vc.size() >= 2) {
        ans = max(ans, solve(vc,c));
        if(n==536)
        cout << solve(vc,c) << " ";
    }
    if(vd.size() >= 2) {
        ans = max(ans, solve(vd,d));
        if(n==536)
        cout << solve(vd,d) << " ";
    }
    if(vc.size() >= 1 && vd.size() >= 1) {
        int b1 = 0, b2 = 0;
        forn(i,0,vc.size()) {
            if(vc[i].fr <= c) b1 = max(b1, vc[i].sc);
        }
        forn(i,0,vd.size()) {
            if(vd[i].fr <= d) b2 = max(b2, vd[i].sc);
        }
        if(b1>0 && b2>0)
        ans = max(ans, b1+b2);
        if(n==536)
        cout << "b1,b2 = " << b1 << " " << b2 << " ";
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

#define forn(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int inf = (int)1e9+5;
const int mod = (int)1e9+7;

bool cmp(int c, pair<int,int> p) {
    return p.fr <= c;
}

int solve(vector<pair<int,int> > v, int c) {
    int n = v.size();
    int mx[n];
    mx[0]=v[0].sc;
    int ans = 0;
    forn(i,1,n) mx[i] = max(mx[i-1],v[i].sc);
    forn(i,1,n) {
        int rem = c - v[i].fr;
        int p = upper_bound(v.begin(), v.begin()+i,rem,cmp) - v.begin();
        if(p==i || (p>=0 && v[p].sc > rem)) --p;
        if(p>=0) {
                //cout << rem << " p = " << p << " " << v[i].sc << " " << mx[p] << endl;
                ans = max(ans, v[i].sc + mx[p]);
        }
    }
    return ans;
}

int main()
{
    int n, c, d;
    cin >> n >> c >> d;
    vector<pair<int,int> > vc, vd;
    forn(i,0,n) {
        int b, p;
        cin >> b >> p;
        char type;
        cin >> type;
        if(type=='C') {
            vc.pb(make_pair(p,b));
        } else {
            vd.pb(make_pair(p,b));
        }
    }
    sort(vc.begin(),vc.end());
    sort(vd.begin(), vd.end());
    int ans = 0;
    if(vc.size() >= 2) {
        ans = max(ans, solve(vc,c));
        if(n==536)
        cout << solve(vc,c) << " ";
    }
    if(vd.size() >= 2) {
        ans = max(ans, solve(vd,d));
       if(n==536)
       cout << solve(vd,d) << " ";
    }
    if(vc.size() >= 1 && vd.size() >= 1) {
        int b1 = 0, b2 = 0;
        forn(i,0,vc.size()) {
            if(vc[i].fr <= c) b1 = max(b1, vc[i].sc);
        }
        forn(i,0,vd.size()) {
            if(vd[i].fr <= d) b2 = max(b2, vd[i].sc);
        }
        if(b1>0 && b2>0)
        ans = max(ans, b1+b2);
       if(n==536)
       cout << "b1,b2 = " << b1 << " " << b2 << " "<< b1+b2 << " ";
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

#define forn(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int inf = (int)1e9+5;
const int mod = (int)1e9+7;

bool cmp(pair<int,int> p, int c) {
    return p.fr <= c;
}

int solve(vector<pair<int,int> > v, int c) {
    int n = v.size();
    int mx[n];
    mx[0]=v[0].sc;
    int ans = 0;
    forn(i,1,n) mx[i] = max(mx[i-1],v[i].sc);
    forn(i,1,n) {
        int rem = c - v[i].fr;
        int p = lower_bound(v.begin(), v.begin()+i-1,rem,cmp) - v.begin();
        if(v[p].fr>rem) --p;
        if(p==i) --p;
        if(p>=0) {
                //cout << rem << " p = " << p << " " << v[i].sc << " " << mx[p] << endl;
                ans = max(ans, v[i].sc + mx[p]);
        }
    }
    return ans;
}

int main()
{
    int n, c, d;
    cin >> n >> c >> d;
    vector<pair<int,int> > vc, vd;
    forn(i,0,n) {
        int b, p;
        cin >> b >> p;
        char type;
        cin >> type;
        if(type=='C') {
            vc.pb(make_pair(p,b));
        } else {
            vd.pb(make_pair(p,b));
        }
    }
    sort(vc.begin(),vc.end());
    sort(vd.begin(), vd.end());
    int ans = 0;
    if(vc.size() >= 2) {
        ans = max(ans, solve(vc,c));
        if(n==536)
       // cout << solve(vc,c) << " ";
    }
    if(vd.size() >= 2) {
        ans = max(ans, solve(vd,d));
        if(n==536)
        //cout << solve(vd,d) << " ";
    }
    if(vc.size() >= 1 && vd.size() >= 1) {
        int b1 = 0, b2 = 0;
        forn(i,0,vc.size()) {
            if(vc[i].fr <= c) b1 = max(b1, vc[i].sc);
        }
        forn(i,0,vd.size()) {
            if(vd[i].fr <= d) b2 = max(b2, vd[i].sc);
        }
        if(b1>0 && b2>0)
        ans = max(ans, b1+b2);
        if(n==536)
        //cout << "b1,b2 = " << b1 << " " << b2 << " ";
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

#define forn(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int inf = (int)1e9+5;
const int mod = (int)1e9+7;

bool cmp(int c, pair<int,int> p) {
    return p.fr <= c;
}

int solve(vector<pair<int,int> > v, int c) {
    int n = v.size();
    int mx[n];
    mx[0]=v[0].sc;
    int ans = 0;
    forn(i,1,n) mx[i] = max(mx[i-1],v[i].sc);
    forn(i,1,n) {
        int rem = c - v[i].fr;
        int p = upper_bound(v.begin(), v.begin()+i-1,rem,cmp) - v.begin();
        if(p>=i) p=-1;
        if(p==i) --p;
        if(p>=0) {
                //cout << rem << " p = " << p << " " << v[i].sc << " " << mx[p] << endl;
                ans = max(ans, v[i].sc + mx[p]);
        }
    }
    return ans;
}

int main()
{
    int n, c, d;
    cin >> n >> c >> d;
    vector<pair<int,int> > vc, vd;
    forn(i,0,n) {
        int b, p;
        cin >> b >> p;
        char type;
        cin >> type;
        if(type=='C') {
            vc.pb(make_pair(p,b));
        } else {
            vd.pb(make_pair(p,b));
        }
    }
    sort(vc.begin(),vc.end());
    sort(vd.begin(), vd.end());
    int ans = 0;
    if(vc.size() >= 2) {
        ans = max(ans, solve(vc,c));
        //if(n==536)
       // cout << solve(vc,c) << " ";
    }
    if(vd.size() >= 2) {
        ans = max(ans, solve(vd,d));
        //if(n==536)
        //cout << solve(vd,d) << " ";
    }
    if(vc.size() >= 1 && vd.size() >= 1) {
        int b1 = 0, b2 = 0;
        forn(i,0,vc.size()) {
            if(vc[i].fr <= c) b1 = max(b1, vc[i].sc);
        }
        forn(i,0,vd.size()) {
            if(vd[i].fr <= d) b2 = max(b2, vd[i].sc);
        }
        if(b1>0 && b2>0)
        ans = max(ans, b1+b2);
        //if(n==536)
        //cout << "b1,b2 = " << b1 << " " << b2 << " ";
    }
    cout << ans;
    return 0;
}