Optimal separation

Given n 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 n followed by n natural
numbers between 1 and 10⁶. Assume 1 ≤ n ≤ 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
