An investor spreads their assets across NINSTRUMENTS financial instruments. Consider one instrument during one term, and let $P$ be the amount it holds at the start of that term. If the instrument is still open, three things happen to it, in order:
FIXED_FEE is deducted.PERCENTAGE_FEE times $P$ — a fraction of the amount held at the start of the term.RETURN times $P$, where RETURN may be positive or negative.Writing the fixed cost as $f$, the percentage fee as $c$, and the return as $r$, the instrument's value at the end of the term is $$P - f - cP + rP.$$
If an account's value becomes zero or negative after a term, it is closed: from then on it is treated as exactly zero and no fees are charged, until a rebalancing reopens it.
A rebalancing happens after every NREBALANCE terms: all instruments' balances are pooled into one total, which is then split among the instruments in proportion to their original starting principals (PRINCIPAL_START). Without rebalancing, the higher-return instruments would gradually dominate the portfolio and expose the investor to more risk than a balanced plan. Every instrument can reach zero at once; then the total is zero, a rebalancing leaves everything at zero, and all accounts stay closed for the remaining terms.
Report the ending value of each instrument after NTERMS terms. If a rebalancing would fall exactly on term NTERMS, report the values before that final rebalancing. Do all arithmetic in double precision without rounding intermediate values, and round only the final answers to the nearest penny (two decimal places).
The first line contains three positive integers:
NINSTRUMENTS NTERMS NREBALANCE
There are at most 10 instruments and at most 20 terms ($1 \le \text{NINSTRUMENTS} \le 10$, $1 \le \text{NTERMS} \le 20$, $\text{NREBALANCE} \ge 1$). This is followed by 3 lines of space-separated floating-point numbers, in this format:
FIXED_FEE(1) .. FIXED_FEE(NINSTRUMENTS)
PERCENTAGE_FEE(1) .. PERCENTAGE_FEE(NINSTRUMENTS)
PRINCIPAL_START(1) .. PRINCIPAL_START(NINSTRUMENTS)
Finally there are NTERMS lines, each with NINSTRUMENTS floating-point numbers giving the return of each instrument in that term:
RETURN(1,1) .. RETURN(1,NINSTRUMENTS)
...
RETURN(NTERMS,1) .. RETURN(NTERMS,NINSTRUMENTS)
All ratios (PERCENTAGE_FEE and RETURN) are given as fractions with up to 4 decimal places. For example, a fee of 0.0002 means 0.02% of the amount invested in that instrument is deducted as a fee each term. FIXED_FEE and PRINCIPAL_START are non-negative floating-point numbers given to 2 decimal places. At least one PRINCIPAL_START value is positive.
Print a single line with the ending principal of each instrument, separated by single spaces, after NTERMS terms. Round each value to the nearest penny (two decimal places), so every value has exactly two digits after the decimal point (a closed account prints as 0.00).
PRINCIPAL_END(1) .. PRINCIPAL_END(NINSTRUMENTS)