#include <bits/stdc++.h>
using namespace std;
const long long N = 210000;
int a[N], b[N], n;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  int p = unique(b, b + n) - b;
  p--;
  int c = b[p], d = b[max(p - 1, 0)];
  for (int i = 0; i < n; i++)
    if (a[i] == c)
      cout << d << endl;
    else
      cout << c << endl;
  return 0;
}
