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