#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 1e6 * 4 + 5;
int n, a[MAXN];
struct SegmentTree {
int l, r;
int dat;
} s[MAXN];
void build(int p, int l, int r) {
s[p].l = l, s[p].r = r;
if (l == r) {
s[p].dat = a[l];
return;
}
int mid = (l + r) >> 1;
build(p * 2, l, mid);
build(p * 2 + 1, mid + 1, r);
s[p].dat = max(s[p * 2].dat, s[p * 2 + 1].dat);
}
void update(int p, int x, int val) {
if (s[p].l == s[p].r) {
s[p].dat = val;
return;
}
int mid = (s[p].l + s[p].r) >> 1;
if (x <= mid)
update(p * 2, x, val);
else
update(p * 2 + 1, x, val);
s[p].dat = max(s[p * 2].dat, s[p * 2].dat);
}
int main() {
scanf ("%d", &n);
for (int i = 1; i <= n; i++) {
scanf ("%d", &a[i]);
}
build(1, 1, n);
return 0;
}