
You are given a 0-indexed m n integer matrix values , representing the values of m n different items in m different shops. Each shop has n items where the j ^th item in the i ^th shop has a value of values[i][j] . Additionally, the items in the i ^th shop are sorted in non-increasing order of value. That is, values[i][j] >= values[i][j + 1] for all 0 <= j < n - 1 .
On each day, you would like to buy a single item from one of the shops. Specifically, On the d ^th day you can:
Pick any shop i .
Buy the rightmost available item j for the price of values[i][j] d . That is, find the greatest index j such that item j was never bought before, and buy it for the price of values[i][j] d .
Note that all items are pairwise different. For example, if you have bought item 0 from shop 1 , you can still buy item 0 from any other shop.
Return the maximum amount of money that can be spent on buying all m * n products .
1 <= m == values.length <= 101 <= n == values[i].length <= 10 ^41 <= values[i][j] <= 10 ^6values[i] are sorted in non-increasing order.