

Free Weights
The city of Bath is a noted olympic training ground — bringing local, national, and even international teams to practice. However, even the finest gymnasium falls victim to the cardinal sin: weights put back in the wrong spots. All of the pairs of dumbbells sit in no particular order on the two racks, possibly even with some of them split between rows. Initially, each row has an equal number of dumbbells, however, this being a wellfunded professional gym, there is infinite space at either end of each to hold any additional weights. To move a dumbbell, you may either roll it to a free neighboring space on the same row with almost no effort, or you may pick it up and lift it to another free spot; this takes strength proportional to its weight. For each pair of dumbbells, both have the same unique weight. What is the heaviest of the weights that you need to be able to lift in order to put identical weights next to each other? Note that you may end up with different numbers of weights on each row after rearranging; this is fine. Input SpecificationThe input consists of:
Every weight in the input appears exactly twice. Output SpecificationOutput the weight of the heaviest dumbbell that must be lifted, in order that all items can be paired up while lifting the smallest possible maximum weight. Sample Input 1
Output for Sample Input 1
Sample Input 2
Output for Sample Input 2


University of Debrecen; Faculty of Informatics; v. 03/01/2019 