Time limit
2s
Memory limit
128 MB
Dongho wants to earn as much money as possible by trading stocks. He knows the prices of C stocks for each of the next D days.
He starts with M units of cash. On each day, he may buy and sell any whole number of shares at that day's listed prices, as long as he only uses the money he currently has. At the end of the last day, all remaining shares are converted back to cash.
Given the stock prices, determine the maximum amount of money Dongho can have after the D days.
The first line contains three integers C, D, and M separated by spaces: the number of stocks, the number of trading days, and the initial amount of money.
1 <= C <= 502 <= D <= 101 <= M <= 200,000Each of the next C lines contains D integers. The j-th integer on the i-th of these lines is the price of stock i on day j. Every stock price is between 1 and 1,000, inclusive.
Print the maximum amount of money Dongho can have at the end.
Only data whose answer does not exceed 500,000 is given.