#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int max = *max_element(a.begin(), a.end()), max2 = 0;
  for (int i : a)
    if (i > max2 && i < max) max2 = i;
  if (max2 == 0) max2 = max;
  for (int i : a)
    if (i == max)
      cout << max2 << endl;
    else
      cout << max << endl;
}
