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