#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  sort(a.begin(), a.end());
  int max = a[n - 1], second = a[n - 2];
  for (int i = 0; i < (n); i++) {
    if (a[i] != max) {
      cout << max << endl;
      continue;
    } else {
      cout << second << endl;
      continue;
    }
  }
}
