#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  int first = 0;
  for (int i = 0; i < N; ++i) {
    if (first < A[i]) {
      first = A[i];
    }
  }
  int second = 0;
  for (int i = 0; i < N; ++i) {
    if (first > A[i] && second < A[i]) {
      second = A[i];
    }
  }
  if (second == 0) {
    second = first;
  }
  for (int i = 0; i < N; ++i) {
    if (A[i] == first) {
      cout << second << endl;
    } else {
      cout << first << endl;
    }
  }
  return 0;
}
