#include <bits/stdc++.h>
int main() {
  int n, m1 = 0, m2 = 0;
  std::cin >> n;
  std::vector<int> a(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
    if (a[i] > m1)
      m1 = a[i];
    else if (a[i] > m2)
      m2 = a[i];
  }
  for (int i = 0; i < n; i++) {
    int ans = (m1 == a[i]) ? m1 : m2;
    std::cout << ans << std::endl;
  }
  return 0;
}
