Given N integers, seperate all of them into two multisets A and B such that the absolute difference between their sums of elements, i.e.
, is minimized.
Notice that:
1. Multiset is a generalization concept of a set that, unlike a set, allows multiple instances of the same element.
2. Either A or B is allowed to be empty, and the sum of elements of an empty multiset is defined as 0.
Input contains multiple test cases.
Each test case starts with a positive integer N, then the next line contains N integers n1, n2, …, nN seperated by single space character. A test case of N = 0 indicates the end of input, and it should not be processed.
For dataset 1, 1≤N≤3, 0≤ni≤100
For dataset 2, 1≤N≤5, 0≤ni≤10000
For dataset 3, 1≤N≤10, 0≤ni≤100000
For dataset 4, 1≤N≤20, -1000000≤ni≤1000000
Hint: Try to enumerate all possible combinitions.
For each testcase, output an integer denoting the minimum value of
in a line.