#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, i, temp, high, ind;
  cin >> n;
  vector<int> a(n), b(n);
  high = 0;
  for (i = 0; i < n; i++) {
    cin >> temp;
    a[i] = temp;
    b[i] = temp;
    if (a[i] > high) {
      high = a[i];
      ind = i;
    }
  }
  sort(b.begin(), b.end());
  if (b[0] == b[1]) {
    for (i = 0; i < n; i++) {
      cout << high << endl;
    }
  } else {
    for (i = 0; i < n; i++) {
      if (a[i] == high) {
        cout << b[1] << endl;
      } else {
        cout << high << endl;
      }
    }
  }
  return 0;
}
