#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m1, m2 = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  m1 = *max_element(a.begin(), a.end());
  for (int i = 0; i < (int)(n); i++) {
    if (a[i] != distance(a.begin(), find(a.begin(), a.end(), m1)) &&
        m2 < a[i]) {
      m2 = a[i];
    }
  }
  for (int i = 0; i < (int)(n); i++) {
    if (a[i] == m1) {
      cout << m2 << endl;
    } else
      cout << m1 << endl;
  }
}
