#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout.precision(30);
  long long n;
  cin >> n;
  vector<long long> L1, L;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    L.push_back(x);
  }
  L1 = L;
  sort(L1.begin(), L1.end());
  long long res = 0;
  for (int i = 0; i < n; i++) {
    if (L[i] != L1[n - 1])
      cout << L1[n - 1];
    else if (L[i] == L1[n - 1] && L[n - 1] == L[n - 2])
      cout << L1[n - 1];
    else
      cout << L1[n - 2];
    cout << "\n";
  }
  return 0;
}
