#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> A(n, 0);
  for (int i = 0; i < (int)(n); i++) cin >> A.at(i);
  int MAX = 0;
  for (int i = 0; i < (int)(n); i++) MAX = max(MAX, A.at(i));
  int submax = 0;
  for (int i = 0; i < (int)(n); i++)
    (A.at(i) == MAX) ?: submax = max(submax, A.at(i));
  if (submax == 0) submax = MAX;
  for (int i = 0; i < (int)(n); i++)
    (A.at(i) == MAX) ? cout << submax << endl : cout << MAX << endl;
}
