ACM Coalition

No attempts yetTime limit1sMemory limit128 MB

Problem

No party won a majority in the recent parliament election, so filling the Management Board takes a coalition. The board has one speaker, two deputy speakers and six secretaries. Voting on the board is weighted: the speaker casts 25 votes, each deputy speaker casts 8 votes, and each secretary casts 1 vote.

The ACM party wants to lead the coalition, but it is mm seats short of a majority. It knows how many seats every other party holds. In return for joining the coalition, a party demands a share of the board as a triplet (a,b,c)(a, b, c), where aa, bb and cc are the numbers of speakers, deputy speakers and secretaries it expects to be chosen from its own ranks. If the party BDN demands (1,1,2)(1, 1, 2), then the speaker, one deputy speaker and two secretaries have to come from BDN. A party may state several demands, and then it joins the coalition as soon as one of them is met.

The seats of the parties that join have to add up to at least mm, which is what covers the shortage of ACM. Every board position left over after the demands are filled goes to ACM. Maximize the total number of votes ACM holds on the board.

Input

The input holds several test cases.

Each test case starts with a line containing two integers nn and mm. Here nn is the number of parties other than ACM (n50n \le 50) and mm is the number of seats ACM is short. The next nn lines describe one party each. Such a line starts with the number of seats that party holds, then a colon, a space, and the list of its demands. A demand has the form (a,b,c)(a, b, c) with 0a10 \le a \le 1, 0b20 \le b \le 2 and 0c60 \le c \le 6. Demands are separated by or, and the list ends with a semicolon.

The last line of the input is 0 0. Every test case admits at least one coalition that covers the mm seats.

Output

For each test case, print one line with three integers: the numbers of speakers, deputy speakers and secretaries that ACM gets in a coalition maximizing its votes.

One speaker outweighs two deputy speakers plus six secretaries, and one deputy speaker outweighs six secretaries, so the vote-maximizing share is unique.