Skip to content
UPEEC

Balanced Load Split

Hard#dynamic-programming· solved by 0 · time limit 2.0 s

Split nn loads (in watts) between two circuits so the difference between the circuits' totals is as small as possible. Print that minimum difference.

Input

nn, then nn positive integers.

Output

The minimum difference.

Constraints

1≤n≤1001 \le n \le 100, 1≤ai≤10001 \le a_i \le 1000

Sample 1

Input

4
1 6 11 5

Output

1

Sample 2

Input

5
3 1 4 2 2

Output

0

Sign in or join free to run and submit your solution.