#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const long long INF = 1e18;
const double pi = 3.14159265358979323846;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int l[n], r[n];
  for (int i = 1; i < n; i++) l[i] = max(l[i - 1], a[i - 1]);
  for (int i = n - 2; i >= 0; i--) r[i] = max(r[i + 1], a[i + 1]);
  for (int i = 0; i < n; i++) cout << max(l[i], r[i]) << endl;
}
