#include <bits/stdc++.h>
using namespace std;
priority_queue<int> Q;
int A[200001];
int main() {
  int a, i, m, s = 0;
  cin >> a;
  for (i = 1; i <= a; i++) cin >> A[i], Q.push(A[i]);
  m = Q.top();
  while (!Q.empty()) {
    s = Q.top(), Q.pop();
    if (s != m) break;
  }
  for (i = 1; i <= a; i++)
    if (A[i] == m)
      cout << s << endl;
    else
      cout << m << endl;
}
