Ctudor (silent 'C') can't buy regular flowers because it's cruel to remove the reproductive organ of a plant for decorative purposes. Instead, he must buy orchids as those are interesting plants to grow. However, it is Valentine's Day and crappy grocery store orchids simply will not do, and Ctudor must buy good orchids from legendary plant collector Dennis. Dennis grows
Ctudor knows exactly which plants he wants and must determine the cheapest way to purchase them. Unfortunately, because his girl does not have enough lighting and plant space, Ctudor cannot buy extra orchids even if that lowers the cost.
Constraints
Input Specification
The first line will contain
The next
The next
The final line will contain
Output Specification
The lowest possible cost to buy all the orchids.
Sample Input 1
2 2
2
5
5 3 0
10 1 2
3 2
Sample Output 1
14
Sample Input 2
3 2
2
3
4
4 1 1 0
9 2 2 1
1 2 1
Sample Output 2
11
Comments