#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[200000];
  cin >> n;
  int maxi = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    maxi = max(maxi, a[i]);
  }
  int maxi2 = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != maxi && maxi2 < a[i]) maxi2 = a[i];
  }
  if (maxi2 == 0) {
    maxi2 = maxi;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == maxi) {
      cout << maxi2 << endl;
    } else {
      cout << maxi << endl;
    }
  }
  return 0;
}
