#SDNU1715. Separated Lunch

Separated Lunch

Problem Statement

As KEYENCE headquarters have more and more workers, they decided to divide the departments in the headquarters into two groups and stagger their lunch breaks.

KEYENCE headquarters have NN departments, and the number of people in the ii-th department (1iN)(1\leq i\leq N) is KiK_i.

When assigning each department to Group AA or Group BB, having each group take lunch breaks at the same time, and ensuring that the lunch break times of Group AA and Group BB do not overlap, find the minimum possible value of the maximum number of people taking a lunch break at the same time.
In other words, find the minimum possible value of the larger of the following: the total number of people in departments assigned to Group AA, and the total number of people in departments assigned to Group BB.

Constraints

  • 2N202 \leq N \leq 20
  • 1Ki1081 \leq K_i \leq 10^8
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

K1K_1 K2K_2 \ldots KNK_N

Output

Print the minimum possible value of the maximum number of people taking a lunch break at the same time.

Sample Input 1

5
2 3 5 10 12

Sample Output 1

17

When assigning departments 11, 22, and 55 to Group AA, and departments 33 and 44 to Group BB, Group AA has a total of 2+3+12=172+3+12=17 people, and Group BB has a total of 5+10=155+10=15 people. Thus, the maximum number of people taking a lunch break at the same time is 1717.

It is impossible to assign the departments so that both groups have 1616 or fewer people, so print 1717.

Sample Input 2

2
1 1

Sample Output 2

1

Multiple departments may have the same number of people.

Sample Input 3

6
22 25 26 45 22 31

Sample Output 3

89

For example, when assigning departments 11, 44, and 55 to Group AA, and departments 22, 33, and 66 to Group BB, the maximum number of people taking a lunch break at the same time is 8989.