#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int ar[n], ma = -999999, sma = -999999;
  for (long long int i = 0; i < n; i++) {
    cin >> ar[i];
    if (ar[i] > ma) {
      ma = ar[i];
    }
    if (ar[i] > sma && ar[i] < ma) {
      sma = ar[i];
    }
  }
  if (sma == -999999) {
    sma = ma;
  }
  for (long long int i = 0; i < n; i++) {
    if (ar[i] == ma) {
      cout << sma << "\n";
    } else {
      cout << ma << "\n";
    }
  }
  return 0;
}
