Last Problem
InterviewTime limit0.5sMemory limit1024 MB
Given N distinct difficulties, find the lowest integer in their range that maximizes the minimum distance to all of them, or -1 if none exists.
Problem
In the year 3023, the PPC problem setters carefully chose problems to use in PPC. Each problem has a difficulty given as an integer from to , and the difficulties are all distinct. A smaller difficulty number means an easier problem.
Problem
The setters will add one final problem. Its difficulty must satisfy both of the following conditions.
It must differ from the difficulty of every existing problem.
It must not be easier than the easiest existing problem, and it must not be harder than the hardest existing problem.
The setters want the difficulty spread to be as even as possible. They will choose the difficulty that maximizes the minimum difference to the existing problems. If several difficulties tie for that maximum, they will choose the lowest one. Find the difficulty of the final problem.
Input
The first line contains (), the number of prepared problems.
The second line contains distinct integers (), separated by spaces.
Output
Print the difficulty of the final problem. If the setters cannot add a final problem, print -1.
Hint
This is the last problem of this contest.