#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> ti(N);
  for (int i = 0; i < N; i++) {
    cin >> ti[i];
  }
  vector<int> copy(N);
  for (int i = 0; i < N; i++) {
    copy[i] = ti[i];
  }
  sort(ti.begin(), ti.end());
  reverse(ti.begin(), ti.end());
  int ma = 0;
  int secma = 0;
  ma = ti[0];
  for (int i = 0; i < N; i++) {
    if (ti[i] != ma) {
      secma = ti[i];
      break;
    }
    if (i == N - 1) secma = ma;
  }
  for (int i = 0; i < N; i++) {
    if (copy[i] == ma)
      cout << secma << endl;
    else
      cout << ma << endl;
  }
}
