#ABC204D. [ABC204D] Cooking

[ABC204D] Cooking

Score : 400400 points

Problem Statement

Takahashi is going to cook NN dishes called Dish 11 through NN.

Dish ii can be cooked by using an oven for TiT_i consecutive minutes. An oven cannot be used for two or more dishes simultaneously.

If Takahashi has two ovens to use, what is the shortest number of minutes needed to cook all the NN dishes? Assume that all processes other than using ovens take negligible time.

Constraints

  • 1N1001 \leq N \leq 100
  • 1Ti1031 \leq T_i \leq 10^3
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

T1T_1 \ldots TNT_N

Output

Print the answer.

5
8 3 7 2 5
13

We can, for example, use the two ovens as follows to cook all the dishes in 1313 minutes.

  • The first oven: Cook Dishes 55 and 11 in this order.
  • The second oven: Cook Dishes 22, 44, and 33 in this order.
2
1000 1
1000
9
3 14 15 9 26 5 35 89 79
138