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
2016-05-01 08:06:03
WA because of the ambiguity of the problem statement as others have complained, the soldier must buy 6 items which means that if you are given less types than 6 "there is no answer". Good luck. :)
2016-02-16 05:04:26 minhthai
why code limit :(
2015-08-04 19:28:33 Raunak jain
incomplete problem statment!

Last edit: 2015-08-15 16:06:00
2015-07-27 18:34:36 Medo
Something is weird in the Judge I/O. Same code gives NZEC error in JAVA when using a Scanner, but AC in C++. ( Same input reading/output formatting). There are still accepted solutions in JAVA, but code this in C/C++ if you can.
2015-06-04 08:49:41 i_am_looser
Don't use fast I/O. will give tle. Don't know why.
2015-04-02 14:43:43 Rajat De
some problem with test data as scanf gives AC but fast IO gives TLE
2015-01-29 01:02:41 sabry_ragab
There can be less than 6 types of items but you must buy 6 items
2014-12-06 01:55:00 Jim Gao
Why did they give me 256MB, I can run Linux under 256MB, and we are totally writing a version of Linux. :P
2014-10-28 14:28:25 californiagurl
I don't believe my solution got AC. It surprised me really.
2014-10-27 07:02:37 newbie
a simple dp problem
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.