#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, mxmx = -2, mxmn = -10;
  cin >> N;
  int A[N];
  bool CAN = false;
  for (int i = (0); i < (N); ++i) {
    cin >> A[i];
    if (A[i] == mxmx) {
      CAN = true;
      break;
    }
    if (mxmx < A[i]) {
      mxmn = mxmx;
      mxmx = A[i];
    }
    if (mxmx > A[i] && mxmn < A[i]) mxmn = A[i];
  }
  if (CAN) {
    for (int i = (0); i < (N); ++i) cout << mxmx << endl;
  } else {
    for (int i = (0); i < (N); ++i) {
      if (A[i] == mxmx)
        cout << mxmn << endl;
      else
        cout << mxmx << endl;
    }
  }
}
