A large supermarket chain has asked you to write a program that simulates the cost of a promotion it is planning.
The promotion follows these rules:
Business is brisk, so you may assume that at the end of every day, just before the largest and smallest receipts are drawn, the box always holds at least two receipts.
Given the receipt amounts dropped into the box on each day of the promotion, compute the total cost of all prizes paid over the whole promotion.
Your program should:
The first line contains one positive integer n (1≤n≤5000): the length of the promotion in days.
Each of the next n lines describes one day. The (i+1)-th line lists the receipt amounts dropped into the box on day i. It begins with an integer k (0≤k≤105), the number of receipts that day, followed by k positive integers giving those receipt amounts; none of these amounts exceeds 106.
The total number of receipts dropped into the box over the whole promotion does not exceed 106.
Print exactly one integer: the total cost of the prizes paid during the whole promotion.