#include <bits/stdc++.h>
using namespace std;
auto main() -> int {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = (0); i < (n); i++) cin >> arr[i];
  set<int> arr1(arr.begin(), arr.end());
  int a = *prev(arr1.end());
  int b = *prev(prev(arr1.end()));
  for (auto i : arr) {
    if (i != a)
      cout << a << "\n";
    else
      cout << b << "\n";
  }
}
