#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int MOD = 1000000007;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const long long INF = 1LL << 60;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
using Graph = vector<vector<int>>;
Graph G;
vector<bool> seen;
void dfs(const Graph &G, int v) {
  seen[v] = true;
  for (auto next_v : G[v]) {
    if (seen[next_v]) continue;
    dfs(G, next_v);
  }
}
int main() {
  long long n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> left_max(n);
  vector<int> right_max(n);
  for (int i = 1; i < n; i++) {
    left_max[i] = max(left_max[i - 1], a[i - 1]);
  }
  for (int i = n - 2; i >= 0; i--) {
    right_max[i] = max(left_max[i + 1], right_max[i + 1]);
  }
  for (int i = 0; i < n; i++) {
    cout << max(left_max[i], right_max[i]) << endl;
  }
}
