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