#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
int main() {
  int n;
  int max = -1;
  int sbmax = -1;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
    if (max < vec[i]) {
      max = vec[i];
      sbmax = max;
    }
  }
  for (int i = 0; i < n; i++) {
    if (vec[i] == max)
      cout << sbmax << endl;
    else
      cout << max << endl;
  }
  return 0;
}
