#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  int A_max = A.at(N - 1);
  int A_second = A.at(N - 2);
  vector<int> B(N);
  int C = 0;
  for (int i = 0; i < N; i++) {
    B.at(i) = A.at(i);
  }
  for (int i = 0; i < N; i++) {
    if (B.at(i) == A_max) {
      C = A_second;
    } else {
      C = A_max;
    }
    cout << C << endl;
  }
}
