King and jewels

The treasure of a country far away is initially empty. Afterwards, the officials of the treasure acquire some jewels (each one with some value) and add them to the treasure one by one.

According to an old tradition, the king of that country has the right to choose and keep for himself up to two thirds of the jewels. Since the king may need to run away from the country at any moment, he always needs to know in an efficient way the maximum total value of the jewels that he can take with him. Can you help the king?

Input

Input consists of several cases. Every case begins with the number nn of jewels acquired by the treasure. Follow the value of the nn jewels, in the order in which they are obtained. Assume 1n1041 \le n \le 10^4, and that the values are integer numbers between 1 and 10910^9.

Output

For every case, and after every acquired jewel, print the maximum total value of the jewels that the king can choose. Print a line with 10 dashes after every case.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:32:03.607Z

© Jutge.org, 2006–2026.
https://jutge.org