#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  long long int n;
  cin >> n;
  long long int arr[n];
  set<long long int> second;
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
    second.insert(arr[i]);
  }
  vector<long long int> v;
  v.assign(second.begin(), second.end());
  long long int max1 = v[v.size() - 1];
  long long int max2;
  if (v.size() == 1)
    max2 = max1;
  else
    max2 = v[v.size() - 2];
  for (long long int i = 0; i < n; i++) {
    if (arr[i] == max1)
      cout << max2 << endl;
    else
      cout << max1 << endl;
  }
  return 0;
}
