import sys
input = sys.stdin.readline
from bisect import bisect_left, bisect_right
# example()
N=int(input())
A=list(map(int, input().split()))
INF=float("inf")
left_u=[-1]*N
left_d=[INF]*N
u,d=-1,INF
for i in range(N):
if u>A[i]:
left_u[i]=u
if dA[i]:
right_u[i]=u
if d