Market Movers
Two groups of market participants are actively trading futures in the chaotic Egyptian stock market. One group are the naive retail investors who try to make a quick buck, but tend to lose money rather than make any profit. The other group is really just one person: trader extraordinaire Maged from Sphinx Trading. Maged is bringing in billions for Sphinx Trading, and these record profits are raising suspicions among the trading community. Majid from Nile River Capital is especially sceptical, and raises what he believes are questionable market movements to the Egyptian authorities.
Currently, there are types of futures contracts in the market. For each type
, there are
contracts available, where each contract has a value of
dollars.
The groups of market participants take turns trading for a total of rounds, with the group of retail investors starting first. In the
th round, the current participant trades exactly
contracts in the market (across any type, without exceeding availability).
As a seasoned trader, Maged makes optimal trades to maximise his profits. The naive group of retail investors, despite thinking they're making optimal trades, end up trading the least valuable contracts, effectively minimising their potential gains.
The market regulators have called upon you to determine whether any suspicious behaviour is taking place by computing the total value of all remaining futures contracts after all rounds. This information will be vital in determining if Maged is suspiciously moving markets!
Input
The first line contains two integers
and
, the number of contract types and the number of turns trading, respectively.
The second line contains space-separated integers
, the number of contracts available for a futures contract of type
.
The third line contains space-separated integers
, the value of the contract of type
.
The last line contains space-separated integers
, the quantity of contracts traded on the
th turn.
Output
Print the total value of all remaining futures contracts after rounds.
Examples
Input 1
4 4
2 1 2 4
2 2 4 4
1 2 2 1
Output 1
12
Explanation
- On the first turn, the group of retail investors trade
contract worth
, trading the least valuable contracts.
- On the second turn, Maged trades
contracts worth
.
- Then, the group of retail investors trade
contracts worth
.
- Finally, Maged trades
contract worth
.
At the end of trading, there are remaining contracts worth
each, resulting in a total remaining value of
.
Input 2
4 2
1 1 2 8
4 1 2 5
1 2
Output 2
38
Comments