#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[200200];
  int maxx1 = 0;
  int maxx2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    maxx1 = max(maxx1, a[i]);
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == maxx1)
      cnt++;
    else
      maxx2 = max(maxx2, a[i]);
    if (cnt == n) maxx2 = maxx1;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == maxx1)
      cout << maxx2 << endl;
    else
      cout << maxx1 << endl;
  }
}
