#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> sorta(n);
  int maxa = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sorta[i] = a[i];
    maxa = max(maxa, a[i]);
  }
  sort(sorta.rbegin(), sorta.rend());
  bool flag = true;
  int seconda;
  for (int i = 0; i < n; i++) {
    if (sorta[i] != maxa) {
      seconda = sorta[i];
      flag = false;
      break;
    } else {
      continue;
    }
  }
  if (flag) {
    for (int i = 0; i < n; i++) {
      cout << maxa << endl;
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (a[i] == maxa) {
        cout << seconda << endl;
      } else {
        cout << maxa << endl;
      }
    }
  }
}
