#include <bits/stdc++.h>
using namespace std;
const long long INF = 1 << 29;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  long long amax = 0;
  long long bmax = 0;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    amax = max(amax, a[i]);
    if (a[i] != amax) {
      bmax = max(bmax, a[i]);
    }
  }
  int cnt = count((a).begin(), (a).end(), amax);
  for (int i = 0; i < (int)(n); i++) {
    if (a[i] != amax) cout << amax << endl;
    if (a[i] == amax) {
      if (cnt >= 2) cout << amax << endl;
      if (cnt == 1) cout << bmax << endl;
    }
  }
}
