LogiQuest

258. Minimum Subset Difference

MediumKnapsack

Split the numbers into two groups to minimise the absolute difference of their sums. Print that minimum.

Input format

Line 1: n Line 2: n positive integers

Output format

The minimum difference.

Example 1

Input

4
1 6 11 5

Output

1

Example 2

Input

2
3 9

Output

6

Constraints

1 ≤ n ≤ 100 1 ≤ values ≤ 1000

Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.

Loading the MyLoginn IDE…