#include <bits/stdc++.h>
int sum;
using namespace std;
int bigG, suneo;
int ans;
int main() {
  int a[200000], n;
  cin >> n;
  for (int i = (int)(0); i < (int)(n); i++) {
    cin >> a[i];
  }
  for (int i = (int)(0); i < (int)(n); i++) {
    if (suneo < a[i] && a[i] < bigG) {
      suneo = a[i];
    }
    if (bigG < a[i]) {
      bigG = a[i];
    }
    if (n == 2) {
      suneo = min(a[0], a[1]);
    }
  }
  for (int i = (int)(0); i < (int)(n); i++) {
    if (bigG == a[i]) {
      cout << suneo << endl;
    } else {
      cout << bigG << endl;
    }
  }
  return 0;
}
