#include <bits/stdc++.h>
using namespace std;
int INF = 100100101;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < (n); ++i) {
    if (a[n - 1] != b[i])
      cout << a[n - 1] << endl;
    else if (a[n - 2] != b[i])
      cout << a[n - 2] << endl;
    else
      cout << a[i] << endl;
  }
}
