PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000047. Chia tiền xu công bằng (Dividing Coins)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chia tiền xu công bằng (Dividing Coins)

Dividing Coins

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

A bag contains nn individual coins with values aia_i. Assign every coin to exactly one of two people; coins cannot be split. Either person may receive no coins. Your task is to minimize the absolute difference between their total values.

Input

The first line contains nn. If n>0n>0, the next line contains the nn coin values aia_i.

Output

Print the smallest difference between the two sums.

Subtasks

The independent scoring groups have the following complete constraints:

  • Subtask 1 (20%): 0≤n≤160\le n\le16, 1≤ai≤201\le a_i\le20.
  • Subtask 2 (30%): 0≤n≤500\le n\le50, 1≤ai≤2001\le a_i\le200.
  • Subtask 3 (50%): 0≤n≤1000\le n\le100, 1≤ai≤5001\le a_i\le500.

Examples

Input

3
2 3 5

Output

0

Explanation

The total is 1010. Give the coin of value 55 to one person and coins 22 and 33 to the other: both receive 55, and the difference is 00.