#include <bits/stdc++.h>
using namespace std;
const int N = 100010, Mod = 998244353;
const double pi = acos(-1.0);
int n, a[N], b[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i];
  sort(b + 1, b + n + 1);
  int mx = b[n], mx2 = b[n - 1];
  for (int i = 1; i <= n; i++)
    if (a[i] != mx)
      cout << mx << endl;
    else
      cout << mx2 << endl;
  return 0;
}
