SOLDIER - Help the soldier

Igor, a famous Russian soldier, must go to war in Afghanistan (we are in late 80’s). His superiors allowed him to buy himself his equipment. So, he must buy 6 items: helmet, bulletproof vest, trousers, boots, tunic and a firearm. This items are represented with numbers from 1 to 6. There are N (6 < N < 101) items of these 6 types. Each item is characterized by its price p[i] (in rublas) and is quality q[i]. Igor has T (0 < T < 1001) rublas and he wants to maximize the total quality of his equipment. The total quality is the quality of the item with the lowest quality. Help him.

Input

On the first line there are two integers N and T. On the lines 2 ... N+1 there are 3 integers, type[i] (from 1 to 6) p[i] and q[i]. (0 < p[i], q[i] < T )

Output

Output the total quality.

Example

Input:
7 53
5 8 2
2 4 8
6 8 13
1 13 12
4 5 1
3 2 7
3 13 5

Output:
1

Note

If there is no answer, output 0.

There can be less than 6 types of items.

[ Edited by EB ]

Warning: Some input files are incomplete and broken.


Added by:Pripoae Toni
Date:2008-09-14
Time limit:0.109s
Source limit:2048B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:Original

hide comments
2010-12-23 06:44:11 Mahesh Chandra Sharma
in some cases type[i] is > 100
will you please fix it?

Last edit: 2010-12-23 06:52:47
2009-08-30 13:50:49 shantanu
hmmmm..... compile time is causing trouble :(
2009-08-05 04:30:50 ~ adieus ~
the limits specified here are not correct. Actual test cases have N,T greater than 101 and 1001 respectively.
2009-06-24 16:38:20 Pripoae Toni
Yes, when there aren't all, you have to output 0, this is the first testcase.
2009-06-15 12:49:53 Tushar Bisht
note : take care of the case of less than 6 items..

Last edit: 2009-07-02 08:07:27
2009-06-07 00:41:30 Essam AlNaggar
Note:
If there is no answer, output 0.
There can be less than 6 types of items.
2009-06-01 08:34:16 .
if there are less then 6 types of items does this mean that there is no answer ? (output 0)
2009-02-17 17:37:10 Luke Pebody
It seems that one of the data set has fewer than N items available.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.