Cinema tickets#5463

Cinema tickets

1 second
128 megabytes
Medium

You are asked to help a cashier sell movie tickets. There are two consecutive free rows, each with seats. The seats in each row are numbered from left to right, from to . People are standing in line in groups of a_i people. Each group can be seated consecutively in any one row, or, if a_i is even, the group can be split and seated in both rows in places with the same numbers.

The cashier is pondering: is it possible to seat all the groups according to these requirements? Help them by finding the minimum length of a row such that it is possible to seat all the groups while observing the constraints.

\InputFileThe first line contains the number of groups (1 \le n \le 1000). The second line contains integers a_1, a_2, \ldots, a_n, where a_i is the number of people in the -th group. The sum of all a_i does not exceed 10^5.

\OutputFilePrint a single integer — the minimum possible length of one row such that all groups can be seated as required.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading