#include <bits/stdc++.h>
using namespace std;
int N, A[200000];
int main() {
  int N;
  cin >> N;
  int ans = 0;
  int max = 0;
  int second = 0;
  int nu_count = 1;
  for (int i = 0; i < N; ++i) cin >> A[i];
  for (int k = 0; k < N; ++k) {
    if (A[k] > max) {
      int nu_count = 1;
      second = max;
      max = A[k];
    } else if (A[k] > second) {
      second = A[k];
    } else if (A[k] == max) {
      nu_count++;
    }
  }
  if (nu_count >= 2) {
    ans = max;
    for (int i = 0; i < N; ++i) {
      cout << ans << endl;
    }
  } else {
    for (int i = 0; i < N; ++i) {
      if (max == A[i]) {
        ans = second;
        cout << ans << endl;
      } else {
        ans = max;
        cout << ans << endl;
      }
    }
  }
  return 0;
}
