#K95297. Minimum Difference Partition

    ID: 38832 Type: Default 1000ms 256MiB

Minimum Difference Partition

Minimum Difference Partition

John is an avid collector of antique coins. He has a collection of n coins, each with a known value. John wishes to divide his coins into two groups such that the absolute difference between the total values of the two groups is minimized.

Let \(S\) be the sum of all coin values and \(s\) be the sum of coins in one group. The goal is to minimize the difference given by:

$$\text{difference} = |(S - s) - s|.$$

Your task is to compute this minimum possible difference.

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains a single integer n (the number of coins).
  2. The second line contains n space-separated integers representing the value of each coin.

outputFormat

Output the minimum possible absolute difference between the sums of the two groups to standard output (stdout).

## sample
4
1 2 3 4
0

</p>