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
2013-12-15 16:31:04 Kre¹imir Kralj
weak test cases, got AC but failed this tc:
6 50
1 100 1
2 100 1
3 100 1
4 100 1
5 100 1
6 100 1

(output should be 0)

Last edit: 2013-12-15 16:31:26
2013-07-20 19:20:06 Erti-Chris Eelmaa
very simple dp, passed first try, though code limit is pointless. had to compress it, and get rid of fastIO :(
2013-06-02 18:44:32 nagato
easy one.....think simple
2013-01-28 11:11:20 Adel Ali
WARNING! :
Input test cases contain items with type that's out of range!! (from 1 to 6)

TOOK ME OVER A WEEK OF WA'S until I handled this wrong input!!

Last edit: 2013-01-28 11:49:11
2012-06-12 06:56:29 Thomas
There can be less than 6 types of items.
2012-05-13 19:52:58 Giorgos Christoglou
i got run time errors what are the limits ?
2012-03-20 13:53:45 vermin92
please please fix the limits....6 runtime errors because of wrong limits...
2011-05-28 05:20:59 sudipto das
Got AC with O(N^2).. lol
2011-02-10 16:43:32 Michael T
Harder to get input special cases than actually solve the problem. Input is really sick.

Last edit: 2011-02-10 16:59:32
2011-02-08 15:20:13 Sudhindra A
Please increase the solution size to more than 2048 bytes.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.