#P1031. 分苹果 (Apple Division)

分苹果 (Apple Division)

Source: CSES Problem Set (Task 1623)
Link: https://cses.fi/problemset/task/1623
Category: Introductory Problems

  • Time limit: 1.00 s
  • Memory limit: 512 MB

There are nn apples with known weights. Your task is to divide the apples into two groups so that the difference between the weights of the groups is minimal.

Input

The first input line has an integer nn: the number of apples.

The next line has nn integers p_1,p_2,…,p_np\_1,p\_2,\dots,p\_n: the weight of each apple.

Output

Print one integer: the minimum difference between the weights of the groups.

Constraints

  • 1≤n≤201 \le n \le 20
  • 1≤p_i≤1091 \le p\_i \le 10^9

Example

Input:

5
3 2 7 4 1

Output:

1

Explanation: Group 1 has weights 2, 3 and 4 (total weight 9), and group 2 has weights 1 and 7 (total weight 8).