Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

C. Fountains

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

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

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

Input

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

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

Output

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

Examples

Input

3 7 6

10 8 C

4 3 C

5 6 D

Output

9

Input

2 4 5

2 5 C

2 1 D

Output

0

Input

3 10 10

5 5 C

5 5 C

10 11 D

Output

10

Note

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

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

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Aug/14/2020 03:51:00 (h1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|