#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, a, b;
  cin >> N;
  int A[200000];
  bool c = false;
  a = 0;
  b = -1;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] > a) {
      b = a;
      a = A[i];
    } else if (A[i] < a && A[i] > b) {
      b = A[i];
    } else if (A[i] == a) {
      c = true;
    }
  }
  if (c) {
    for (int i = 0; i < N; i++) {
      cout << a << "\n";
    }
  } else {
    for (int i = 0; i < N; i++) {
      if (A[i] != a) {
        cout << a << "\n";
      } else {
        cout << b << "\n";
      }
    }
  }
}
