CF176A Trading Business
Description
To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible.
The system has $ n $ planets in total. On each of them Qwerty can buy or sell items of $ m $ types (such as food, medicine, weapons, alcohol, and so on). For each planet $ i $ and each type of items $ j $ Qwerty knows the following:
- $ a_{ij} $ — the cost of buying an item;
- $ b_{ij} $ — the cost of selling an item;
- $ c_{ij} $ — the number of remaining items.
It is not allowed to buy more than $ c_{ij} $ items of type $ j $ on planet $ i $ , but it is allowed to sell any number of items of any kind.
Knowing that the hold of Qwerty's ship has room for no more than $ k $ items, determine the maximum profit which Qwerty can get.
Input Format
The first line contains three space-separated integers $ n $ , $ m $ and $ k $ ( $ 2
Output Format
Print a single number — the maximum profit Qwerty can get.
Explanation/Hint
In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type ( $ 3·6+7·8=74 $ ). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets $ 3·9+7·9=90 $ units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case.