#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  ll n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  int max1 = max(a[0], a[1]), max2 = min(a[0], a[1]);
  for (int i = 0; i < (n); ++i) {
    if (a[i] > max1) {
      max2 = max1;
      max1 = a[i];
    } else if (a[i] < max1 && a[i] > max2)
      max2 = a[i];
  }
  for (int i = 0; i < (n); ++i) {
    if (a[i] == max1)
      cout << max2 << endl;
    else
      cout << max1 << endl;
  }
  return 0;
}
