#include <bits/stdc++.h>
using namespace std;
const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;
long long dx[] = {0, 0, -1, 1, -1, -1, 1, 1};
long long dy[] = {1, -1, 0, 0, 1, -1, -1, 1};
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  a %= b;
  return gcd(b, a);
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n), pre(n), suf(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  pre[0] = v[0];
  suf[n - 1] = v[n - 1];
  for (int i = 1; i < n; ++i) {
    pre[i] = max(pre[i - 1], v[i]);
  }
  for (auto i = n - 2; i >= 0; --i) {
    suf[i] = max(suf[i + 1], v[i]);
  }
  for (int i = 0; i < n; ++i) {
    if (i == 0) {
      cout << suf[i] << '\n';
    } else if (i == n - 1) {
      cout << pre[i] << '\n';
    } else {
      cout << max(pre[i - 1], suf[i + 1]) << '\n';
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
