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