#include <bits/stdc++.h>
using namespace std;
const int cm = 1 << 17;
char cn[cm], *ci = cn + cm;
inline char getcha() {
  if (ci - cn == cm) {
    fread(cn, 1, cm, stdin);
    ci = cn;
  }
  return *ci++;
}
inline int getint() {
  char C = getcha();
  int A = C - '0';
  while ((C = getcha()) >= '0') A = A * 10 + C - '0';
  return A;
}
const int dm = 1 << 20;
char dn[dm], *di = dn;
inline void putint(int X) {
  int keta = 0;
  char C[10];
  while (X) {
    *(C + keta) = '0' + X % 10;
    X /= 10;
    keta++;
  }
  for (int i = keta - 1; i >= 0; i--) *di++ = (*(C + i));
  *di++ = '\n';
}
int n;
char c[6];
inline void putsaidai() {
  for (int i = n - 1; i >= 0; i--) *di++ = c[i];
  *di++ = '\n';
}
int main() {
  int N = getint();
  int A[200000];
  int saidai = 0;
  int niban = 0;
  for (int i = 0; i < (N); i++) {
    A[i] = getint();
    if (niban < A[i]) {
      niban = A[i];
      if (niban > saidai) swap(niban, saidai);
    }
  }
  int kari = saidai;
  while (kari) {
    *(c + n) = '0' + kari % 10;
    kari /= 10;
    n++;
  }
  for (int i = 0; i < (N); i++) {
    if (A[i] == saidai)
      putint(niban);
    else
      putsaidai();
  }
  fwrite(dn, 1, di - dn, stdout);
  return 0;
}
