#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m1 = 0, m2;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  vector<int> t = v;
  sort(t.begin(), t.end());
  m1 = t[t.size() - 1], m2 = t[t.size() - 2];
  for (int i = 0; i < n; i++) {
    if (m1 == m2) {
      cout << m1 << endl;
    } else if (m1 == v[i]) {
      cout << m2 << endl;
    } else {
      cout << m1 << endl;
    }
  }
}
