#include <bits/stdc++.h>
using namespace std;
vector<int> getList(int i) {
  int a;
  vector<int> vec(i);
  for (int j = 0; j < i; ++j) {
    cin >> a;
    vec.at(j) = a;
  }
  return vec;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> vec = getList(n);
  vector<int> backUp = vec;
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int ma = vec.at(0);
  int second = vec.at(1);
  for (int i = 0; i < n; ++i) {
    if (vec.at(i) == ma) {
      cout << second << endl;
    } else {
      cout << ma << endl;
    }
  }
}
