#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];
  }
  sort((a).begin(), (a).end());
  amax = a[n - 1];
  bmax = a[n - 2];
  for (int i = 0; i < (int)(n); i++) {
    if (a[i] != amax) cout << amax << endl;
    if (a[i] == amax) {
      cout << bmax << endl;
    }
  }
}
