In the capital of the kingdom of Bubeya the Second, a new bridge has been constructed, and it has been decided to embellish it with statues crafted by the finest artisans. For this purpose, artisans were chosen, each contributing one statue. However, the statues vary in weight, and if they are placed randomly on either side of the bridge, there is a risk that one side may become too heavy, causing the bridge to tip. Despite this, the project has already received approval from His Majesty, and all statues must be used. Your task is to determine the optimal way to distribute the statues between the left and right sides of the bridge.
First, you will receive the number (a natural number not exceeding ), followed by natural numbers (each not exceeding ) representing the weights of the statues.
Output a single number: the smallest possible difference in the total weight of the statues between the left and right sides of the bridge. You may place any number of statues on each side.
Example 1