#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  long long b[n], i, temp1, temp2;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a, a + n);
  temp1 = a[n - 1];
  temp2 = a[n - 2];
  for (i = 0; i < n; i++) {
    if (a[i] == temp1)
      cout << temp2 << endl;
    else
      cout << temp1 << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}
