#include <bits/stdc++.h>
using namespace std;
int N;
int A[200000];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", &A[i]);
  int max0 = 0, max1 = 0;
  int max0cnt = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] > max0) {
      max1 = max0;
      max0 = A[i];
      max0cnt = 1;
    } else if (A[i] = max0) {
      max0cnt++;
    } else if (A[i] > max1) {
      max1 = A[i];
    }
  }
  for (int i = 0; i < N; i++) {
    if (A[i] == max0) {
      cout << (max0cnt > 1 ? max0 : max1) << endl;
    } else {
      cout << max0 << endl;
    }
  }
  return 0;
}
