#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int max = 0;
  int max2 = 0;
  int cnt = 0;
  int temp;
  bool flag = false;
  for (int i = 0; i < N; i++) {
    cin >> temp;
    A.at(i) = temp;
    if (temp == max) {
      cnt++;
      continue;
    }
    if (max < temp) {
      max = temp;
      cnt = 1;
      continue;
    }
    if (max2 < temp) {
      max2 = temp;
    }
  }
  if (cnt >= 2) {
    for (int i = 0; i < N; i++) {
      cout << max << endl;
    }
  } else {
    for (int i = 0; i < N; i++) {
      if (A.at(i) != max) {
        cout << max << endl;
      } else {
        cout << max2 << endl;
      }
    }
  }
  return 0;
}
