#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int max = INT_MIN;
  int max2 = INT_MIN;
  for (int i = 0; i < n; i++) {
    if (a[i] > max) max = a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] > max2 && a[i] != max) max2 = a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == max && max2 != INT_MIN)
      cout << max2 << '\n';
    else
      cout << max << '\n';
  }
  return 0;
}
