
class Ostrov:
    def __init__(self, zac, kon, vyska, maxima):
        self.zac, self.kon, self.vyska, self.maxima = zac, kon, vyska, maxima

N = int( input() )
data = [ int(_) for _ in input().split() ]
pohorie = [ data[0] ]
for x in data[1:]:
    if x != pohorie[-1]:
        pohorie.append(x)
N = len(pohorie)

udalosti = [ (pohorie[n],n) for n in range(N) ]
udalosti = list(reversed(sorted(udalosti)))

everest = max(pohorie)
prominencia = [ everest if pohorie[n]==everest else 0 for n in range(N) ]

ostrovy = []
tu_zacina = [ -1 for n in range(N) ]
tu_konci = [ -1 for n in range(N) ]

for vyska, kde in udalosti:
    ma_pred = (kde > 0 and tu_konci[kde-1] != -1)
    ma_za = (kde < N-1 and tu_zacina[kde+1] != -1)
    if (not ma_pred) and (not ma_za):
        ostrovy.append( Ostrov(kde, kde, pohorie[kde], [kde]) )
        tu_zacina[kde] = tu_konci[kde] = len(ostrovy)-1
        continue
    if (not ma_za):
        o = tu_konci[kde-1]
        tu_konci[kde-1] = -1
        tu_konci[kde] = o
        ostrovy[o].kon = kde
        continue
    if (not ma_pred):
        o = tu_zacina[kde+1]
        tu_zacina[kde+1] = -1
        tu_zacina[kde] = o
        ostrovy[o].zac = kde
        continue
    o1, o2 = tu_konci[kde-1], tu_zacina[kde+1]
    tu_konci[kde-1] = tu_zacina[kde+1] = -1
    if ostrovy[o1].vyska == ostrovy[o2].vyska:
        if len(ostrovy[o1].maxima) < len(ostrovy[o2].maxima): o1, o2 = o2, o1
        ostrovy[o1].maxima += ostrovy[o2].maxima
    else:
        if ostrovy[o1].vyska < ostrovy[o2].vyska: o1, o2 = o2, o1
        for x in ostrovy[o2].maxima: prominencia[x] = pohorie[x] - pohorie[kde]
    ostrovy[o1].zac = min(ostrovy[o1].zac, ostrovy[o2].zac);
    ostrovy[o1].kon = max(ostrovy[o1].kon, ostrovy[o2].kon);
    tu_zacina[ ostrovy[o1].zac ] = tu_konci[ ostrovy[o1].kon ] = o1;

for x in prominencia:
    if x > 0:
        print(x)
