SP726 PRO - Promotion
Description
A large Bytelandian supermarket chain has asked you to write a program for the simulating costs of a promotion being prepared.
The promotion has to follow the following rules:
- A customer who wants to participate in the promotion, writes on the receipt, paid by himself, his personal details and throws it into a special ballot box.
- At the end of every day of the promotion, two bills are taken out from the ballot box:
- first, the receipt amounting to the largest sum is chosen,
- then the receipt amounting to the smallest sum is chosen;
The customer who has paid the largest sum gets a money prize equal to the difference between the sum on his bill and the sum on the bill amounting to the smallest sum.
- To avoid multiple prizes for one purchase, both bills selected according to the above rules are not returned to the ballot box, but all remaining bills still participate in the promotion.
The turnover of the supermarket is very big, thus an assumption can be made, that at the end of every day, before taking out receipts amounting to the largest and the smallest sum, there are at least 2 receipts in the ballot box.
Your task is to compute (on the basis of information about prices on receipts thrown into the ballot box on each day of promotion) what the total cost of prizes during the whole promotion will be.
Write a program, which: reads from the standard input a list of prices on receipts thrown into the ballot box on each day of the promotion, computes the total cost of prizes paid in consecutive days of promotion, then writes the result to the standard output.
Input Format
The first line of the input contains one positive integer n (1
Output Format
The output should contain exactly one integer, equal to the total cost of prizes paid during the whole promotion.