Optimal separation

Given nn natural numbers, find how to separate them into two sets so that the absolute value of the difference between the sums of the elements of the two sets is minimized.

Input

Input consists of several cases, each with nn followed by nn natural numbers between 1 and 10610^6. Assume 1n231 \le n \le 23.

Output

For every case, print the minimum possible difference.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T11:20:43.263Z

© Jutge.org, 2006–2026.
https://jutge.org