#include <bits/stdc++.h>
using namespace std;
long long dp[1000001] = {0};
void solve() {
  long long n, max, m;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i];
  if (arr[0] > arr[1]) {
    max = arr[0], m = arr[1];
  } else {
    max = arr[1], m = arr[0];
  }
  for (long long i = 0; i < n; i++) {
    if (arr[i] > max) max = arr[i];
  }
  for (long long i = 0; i < n; i++) {
    if (arr[i] > m && arr[i] != max) m = arr[i];
  }
  for (long long i = 0; i < n; i++) {
    if (arr[i] == max)
      cout << m << "\n";
    else
      cout << max << "\n";
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
