#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 123;
int n, m;
int a[N];
int b[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  int cnt = 0;
  sort(b + 1, b + 1 + n);
  for (int i = 1; i <= n; i++)
    if (a[i] == b[n]) cnt++;
  for (int i = 1; i <= n; i++) {
    if (a[i] == b[n] && cnt <= 0)
      cout << b[n - 1] << '\n';
    else {
      cout << b[n] << '\n';
      cnt--;
    }
  }
  return (0);
}
