#include <bits/stdc++.h>
using namespace std;
const long mod = 1000000007;
int main() {
  long N;
  cin >> N;
  long A[200009];
  for (int i = 1; i <= N; i++) cin >> A[i];
  long B[200009];
  for (int i = 1; i <= N; i++) B[i] = A[i];
  sort(A + 1, A + N + 1);
  long mymax = A[N];
  long secmax = A[N];
  for (int i = N; i >= 1; i--)
    if (A[i] != mymax) {
      secmax = A[i];
      break;
    }
  for (int i = 1; i <= N; i++) {
    if (B[i] == mymax) cout << secmax << endl;
    if (B[i] != mymax) cout << mymax << endl;
  }
}
