IntermediateRating 1100
Smash the Stones
Each turn, take the two heaviest stones x ≤ y and smash them. If x = y both disappear; otherwise one stone of weight y − x is left. Stop when at most one stone remains and print its weight (0 if none).
Input
n, then n weights.
Output
One integer.
Sample 1
Input
6 2 7 4 1 8 1
Output
1
Sample 2
Input
1 1
Output
1
Output appears here