#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1e+14;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
void Yes() {
  cout << "Yes" << endl;
  exit(0);
}
void No() {
  cout << "No" << endl;
  exit(0);
}
int main() {
  long long N;
  cin >> N;
  vector<long long> A(200010);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  long long ma1 = 0;
  for (int i = 0; i < N; i++) {
    long long b = A[i];
    ma1 = max(ma1, b);
  }
  bool ok = true;
  for (int i = 0; i < N - 1; i++) {
    if (A[i] != A[i + 1]) ok = false;
  }
  if (ok) {
    for (int i = 0; i < N; i++) {
      cout << ma1 << endl;
    }
  } else {
    long long ma2 = 0;
    for (int i = 0; i < N; i++) {
      if (A[i] == ma1)
        continue;
      else {
        long long b = A[i];
        ma2 = max(ma2, b);
      }
    }
    for (int i = 0; i < N; i++) {
      if (A[i] == ma1)
        cout << ma2 << endl;
      else
        cout << ma1 << endl;
    }
  }
}
