#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, a[200000], b[20000], max = 200001, cnt = 0, second;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < N; i++) {
    b[i] = a[i];
  }
  sort(a, a + N);
  max = a[N - 1];
  for (int i = N - 1; i >= 0; i--) {
    if (a[i] == max) {
      cnt++;
    } else if (a[i] != max) {
      second = a[i];
      break;
    }
  }
  if (cnt >= 2) {
    for (int i = 0; i < N; i++) {
      cout << max << endl;
    }
  } else {
    for (int i = 0; i < N; i++) {
      if (b[i] != max) {
        cout << max << endl;
      } else {
        cout << second << endl;
      }
    }
  }
}
