#include <bits/stdc++.h>
using namespace std;
const int INFTY = 1 << 21;
int L[50000], R[50000];
void merge(int A[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  for (int i = 0; i < n1; i++) L[i] = A[left + i];
  for (int i = 0; i < n2; i++) R[i] = A[mid + i];
  L[n1] = R[n2] = INFTY;
  int i = 0, j = 0;
  for (int p = left; p < right; p++) {
    if (L[i] <= R[j])
      A[p] = L[i++];
    else
      A[p] = R[j++];
  }
}
void sort(int A[], int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    sort(A, left, mid);
    sort(A, mid, right);
    merge(A, left, mid, right);
  }
}
int main() {
  int n, max = 0, p;
  cin >> n;
  int A[200005];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    if (A[i] > max) {
      max = A[i];
      p = i;
    }
  }
  sort(A, 0, n);
  for (int i = 0; i < n; i++) {
    if (i == p)
      cout << A[n - 2] << endl;
    else
      cout << A[n - 1] << endl;
  }
  return 0;
}
