Now that inflation is under control the tax base is fairly stable, and hence the Infernal Revenue Department is desperately seeking more ways of extracting more money from the citizenry. One proposal is to institute a capital gains tax - in particular a tax made on the profit realised by buying and selling shares on the Stock Exchange. This seems to be a safe bet, since most ordinary people are not involved and therefore it will only affect the ``rich'' who can afford to pay. However, the Society of Creative Acountants has heard of these proposals and realise that it could well affect them.
The problem arises from the fact that shares do not have a fixed (or even steadily moving) price, and thus one has to determine which of the entire portfolio were sold. IRD have identified two ways of determining this; called respectively First Bought, First Sold (FBFS) and Last Bought, First Sold (LBFS). These are most easily explained by an example. Assume that you bought 10000 shares at 100c per share, then bought another 10000 at 90c per share and then sold 15000 shares at 95c per share. The sale will realise $14,250. Under the FBFS method you will be deemed to have sold the oldest stocks first so they will have cost you $10,000 plus $4,500, i.e. $14,500. You have therefore suffered a loss of of $250 and would not be liable for tax. Under the LBFS scheme, you are deemed to have sold the youngest shares first and hence these would have cost $9000 plus $5000, a total of $14,000, meaning you would have to pay tax on $250.
Write a program that will read in a series of share transactions, and for each share determine which method is the optimum. The optimum is the one that minimises the profit (if both earn a profit) or maximises the loss (if at least one makes a loss). In case of a tie, choose LBFS.