#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
const long long M = 1e9 + 7;
long long Max(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long Min(long long a, long long b) {
  if (a > b) return b;
  return a;
}
long long big_mul(long long a, long long b, long long m) {
  long long x = 0, y = a % m;
  while (b > 0) {
    if (b & 1) x = (x + y) % m;
    y = (2 * y) % m;
    b >>= 1;
  }
  return x % m;
}
long long big_mod(long long a, long long b, long long m) {
  long long x = 1, y = a % m;
  while (b > 0) {
    if (b & 1) x = (x * y) % m;
    y = (y * y) % m;
    b >>= 1;
  }
  return x % m;
}
long long Big_mod(long long a, long long b, long long m) {
  long long x = 1, y = a % m;
  while (b > 0) {
    if (b & 1) x = big_mul(x, y, m);
    y = big_mul(y, y, m);
    b >>= 1;
  }
  return x % m;
}
long long mod_inverse(long long a, long long m) { return big_mod(a, m - 2, m); }
void build_tree(vector<pair<long long, pair<long long, long long> > > &tree,
                vector<long long> &vec, long long index, long long l,
                long long r) {
  if (l == r) {
    tree[index] = make_pair(vec[l], make_pair(l, r));
    return;
  }
  int mid = (l + r) / 2;
  build_tree(tree, vec, 2 * index + 1, l, mid);
  build_tree(tree, vec, 2 * index + 2, mid + 1, r);
  tree[index].second.first = l;
  tree[index].second.second = r;
  tree[index].first = Max(tree[2 * index + 1].first, tree[2 * index + 2].first);
}
long long ans(vector<pair<long long, pair<long long, long long> > > &tree,
              long long index, long long a, long long b) {
  long long l = tree[index].second.first;
  long long r = tree[index].second.second;
  if (a > r || b < l) return 0;
  if (a <= l && b >= r) return tree[index].first;
  return Max(ans(tree, 2 * index + 1, a, b), ans(tree, 2 * index + 2, a, b));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  vector<long long> vec;
  vector<pair<long long, pair<long long, long long> > > tree(5 * N);
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    vec.push_back(a);
  }
  build_tree(tree, vec, 0, 0, n - 1);
  for (int i = 0; i < n; i++) {
    long long p = ans(tree, 0, 0, i - 1);
    long long q = ans(tree, 0, i + 1, n - 1);
    cout << Max(p, q) << endl;
  }
  return 0;
}
