#P7535. [COCI 2016/2017 #4] Kas

[COCI 2016/2017 #4] Kas

Problem Description

Kile and Pogi found NN banknotes on the road. Each of them will take some banknotes so that the total amount each person gets is the same. At the same time, they want this total amount to be as large as possible.

Next, they will take the remaining banknotes to a casino. Because they are very lucky, after using the remaining amount as a bet, they will get double that amount. Then, they will split the obtained money equally again and add it to each person’s total amount.

Find the total amount of money each person can get.

Input Format

The first line contains an integer NN.

The next NN lines each contain a positive integer cic_i, representing the value of the ii-th banknote. It is guaranteed that the total value of all NN banknotes does not exceed 10510^5.

Output Format

Output the total amount of money each person can get.

4
2
3
1
6
6
5
2
3
5
8
13
18

Hint

[Sample 1 Explanation]

Kile can choose the banknotes with values 2,3,12,3,1, and Pogi can choose the banknote with value 66. Since there are no remaining banknotes, the total amount each person gets is 66.

[Sample 2 Explanation]

Kile can choose the banknotes with values 5,85,8, and Pogi can choose the banknote with value 1313. The remaining banknotes have values 2,32,3, so after going to the casino, the total amount each person gets is 13+2+3=1813+2+3=18.

[Constraints]

For 50%50\% of the testdata, N13N \le 13.

For 70%70\% of the testdata, N50N \le 50, ci1000\sum c_i \le 1000.

For 100%100\% of the testdata, 1N5001 \le N \le 500.

[Notes and Explanation]

This problem is translated from COCI 2016-2017 CONTEST #4 T3 Kas.

The score of this problem follows the original COCI settings, with a full score of 100100.

Translated by ChatGPT 5