#include <bits/stdc++.h>
using namespace std;
void printVec(std::vector<int>& vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}
template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}
int main() {
  int N;
  cin >> N;
  int maxx = 0;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    maxx = max(maxx, a[i]);
  }
  for (int i = 0; i < N; i++) {
    if (a[i] == maxx) {
      vector<int> b(a);
      remove(b, i);
      vector<int>::iterator iter = max_element(b.begin(), b.end());
      size_t index = distance(b.begin(), iter);
      cout << b[index] << endl;
    } else {
      cout << maxx << endl;
    }
  }
  return 0;
}
