human
Solve in Python:
For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations.

Max is a young biologist. For $n$ days he watched a specific shark, and now he knows the distance the shark traveled in each of the days. All the distances are distinct. Max wants to know now how many locations the shark visited. He assumed there is such an integer $k$ that if the shark in some day traveled the distance strictly less than $k$, then it didn't change the location.
otherwise, if in one day the shark traveled the distance greater than or equal to $k$.
then it was changing a location in that day. Note that it is possible that the shark changed a location for several consecutive days, in each of them the shark traveled the distance at least $k$.

The shark never returned to the same location after it has moved from it. Thus, in the sequence of $n$ days we can find consecutive nonempty segments when the shark traveled the distance less than $k$ in each of the days: each such segment corresponds to one location. Max wants to choose such $k$ that the lengths of all such segments are equal.

Find such integer $k$, that the number of locations is as large as possible. If there are several such $k$, print the smallest one.

-----Input-----

The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of days.

The second line contains $n$ distinct positive integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the distance traveled in each of the day.

-----Output-----

Print a single integer $k$, such that   the shark was in each location the same number of days,  the number of locations is maximum possible satisfying the first condition,  $k$ is smallest possible satisfying the first and second conditions. 

-----Examples-----
Input
8
1 2 7 3 4 8 5 6

Output
7
Input
6
25 1 2 3 14 36

Output
2

-----Note-----

In the first example the shark travels inside a location on days $1$ and $2$ (first location),...
assistant
#Here is Python code to find such integer $k$, that the number of locations is as large as possible.

# https://codeforces.com/problemset/problem/982/D

class Union:
    def __init__(self, n):
        self.p    = {i:i for i in range(n)}
        self.rank = {i:1 for i in range(n)} 
        
    def find(self, x):
        if x < 0: return x
    
        if self.p[x] != x:
            self.p[x] = self.find(self.p[x])
            
        return self.p[x]
    
    def union(self, x, y):
        if x < 0 or y < 0:return
        
        x = self.find(x)
        y = self.find(y)
        
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.p[x]     = y
                self.rank[y] += self.rank[x]
            else:
                self.p[y]     = x
                self.rank[x] += self.rank[y]

def add(d, key, val):
    if key not in d:
        d[key] = 0
    d[key] += val     
    
    if d[key] == 0:
        del d[key]
    
def update(i, used, d, u):
    used[i]  = True
    add(d, 1, 1)
    
    if  i - 1 >=  0 and used[i-1] == True:
        par_1   =  u.find(i)
        par_2   =  u.find(i-1)
        
        size_1  =  u.rank[par_1]
        size_2  =  u.rank[par_2]
    
        add(d, size_1, -1)
        add(d, size_2, -1)
        add(d, size_1+size_2, 1) 
        
        u.union(par_1, par_2)
    
    if i + 1 < n and used[i+1] == True:
        par_1   =  u.find(i)
        par_2   =  u.find(i+1)
        
        size_1  =  u.rank[par_1]
        size_2  =  u.rank[par_2]
    
        add(d, size_1, -1)
        add(d, size_2, -1)
        add(d, size_1+size_2, 1)
        
        u.union(par_1, par_2) 

n   = int(input())
a_  = list(map(int, input().split()))
a   = [(i, x) for i, x in enumerate(a_)]
a   = sorted(a, key=lambda x:x[1])

u    = Union(n)
d    = {}
used = [False] * n
ans        = -1
max_length = -1

for (index, val) in a:
    update(index, used, d, u)
    #print(d, val)
    
    if len(d) == 1:
        len_ = list(d.values())[0]
        
        if max_length < len_:
            max_length = len_
            ans        = val+1
        
print(ans)  

#8
#1 12 2 11 10 3 9 4 8 5 14 6