#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pp = pair<ll, ll>;
const ll amari = 1e9 + 7;
const char BC = 'A' - 'a';
int main() {
  int n;
  cin >> n;
  int maxi = 0;
  int a[n];
  int ok = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    maxi = max(maxi, a[i]);
    if (a[i - 1] != a[i] && i != 0) ok = 1;
  }
  if (!ok) {
    for (int i = 0; i < n; i++) {
      cout << maxi << endl;
    }
  } else {
    int maxii = 0;
    for (int i = 0; i < n; i++) {
      if (maxii < a[i] && a[i] != maxi) {
        maxii = max(maxii, a[i]);
      }
    }
    for (int i = 0; i < n; i++) {
      if (a[i] == maxi)
        cout << maxii << endl;
      else
        cout << maxi << endl;
    }
  }
  return 0;
}
