#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int &e : A) cin >> e;
  vector<int> B = A;
  sort(B.rbegin(), B.rend());
  
  for (int i = 0; i < N; i++) {
    if (A[i] == B[0]) cout << B[1] << endl;
    else cout << B[0] << endl;
  }
}