#include <bits/stdc++.h>
using namespace std;
vector<int> A;
int main() {
  int N;
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  int MAX = 0;
  int sec_max = 0;
  for (int i = 0; i < N; i++) {
    MAX = max(MAX, A[i]);
  }
  for (int i = 0; i < N; i++) {
    if (A[i] != MAX) sec_max = max(sec_max, A[i]);
  }
  if (sec_max == 0) sec_max = MAX;
  for (int i = 0; i < N; i++) {
    if (A[i] == MAX)
      cout << sec_max << endl;
    else
      cout << MAX << endl;
  }
}
