#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, max1 = -99999, max2 = -9999999;
  bool flg = 0;
  cin >> N;
  int* p = new int[N];
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    if (p[i] == max1) {
      flg = 1;
    }
    if (p[i] > max1) {
      max1 = p[i];
      flg = 0;
    }
    if (p[i] < max1 && p[i] > max2) {
      max2 = p[i];
    }
  }
  for (int i = 0; i < N; i++) {
    if (p[i] == max1) {
      if (flg) {
        cout << max1 << '\n';
      } else {
        cout << max2;
      }
    } else {
      cout << max1 << '\n';
    }
  }
}
