Greeting Card Envelopes

Partition up to 15 card types into at most k groups so the total waste, where each group's waste uses one enclosing envelope sized to the group's max width and max height, is minimized.

Medium7Dynamic programmingBit manipulationBrute forceGreedyNo attempts yetTime limit3sMemory limit512 MB

Problem

Your greeting card company makes cards in many different sizes. The designers pick whatever dimensions they like, so there are many card types, and each type has a quantity you must manufacture.

You have to order envelopes for these cards. There is a hard limit on how many different envelope sizes you may order, and that limit can be smaller than the number of distinct card sizes. Every card has to fit inside some envelope, possibly with room to spare, and the wasted paper must be as small as possible. Waste is measured per card as the area of the envelope minus the area of the card. A 10×410 \times 4 card in a 10×410 \times 4 envelope wastes nothing, while the same card in a 12×512 \times 5 envelope wastes 2020. You may not rotate a card to make it fit.

Suppose you have five card types: 10×1010 \times 10 (5 cards), 9×89 \times 8 (10 cards), 4×124 \times 12 (20 cards), 12×412 \times 4 (8 cards), and 2×32 \times 3 (16 cards).

If you can buy only one envelope type, every card has to fit in it, so the smallest usable envelope is 12×1212 \times 12 with area 144144. The waste per card type is 14410×10=44144 - 10 \times 10 = 44, 1449×8=72144 - 9 \times 8 = 72, 1444×12=96144 - 4 \times 12 = 96, 14412×4=96144 - 12 \times 4 = 96, and 1442×3=138144 - 2 \times 3 = 138. The total waste is 44×5+72×10+96×20+96×8+138×16=583644 \times 5 + 72 \times 10 + 96 \times 20 + 96 \times 8 + 138 \times 16 = 5836.

If you can buy two envelope types, the best choice puts the 10×1010 \times 10, 9×89 \times 8, and 12×412 \times 4 cards in 12×1012 \times 10 envelopes and the 4×124 \times 12 and 2×32 \times 3 cards in 4×124 \times 12 envelopes, for a total waste of 18281828.

If you can buy five envelope types, you can match one envelope to each card type and waste nothing.

Given the list of card types and the number of envelope types you may buy, find the smallest possible amount of wasted paper.

Input

The first line contains two space separated integers nn and kk (1n,k151 \le n, k \le 15), where nn is the number of card types and kk is the maximum number of envelope types you may order.

Each of the next nn lines contains three space separated integers ww, hh, and qq (1w,h,q100001 \le w, h, q \le 10000) describing one card type: ww is the width of these cards, hh is the height, and qq is the quantity.

Output

Print a single integer, the smallest possible total area of wasted paper.