#include <bits/stdc++.h>
using namespace std;
int n;
struct node {
  int num, id, max;
} a[100005];
bool cmp(node x, node y) { return x.num < y.num; }
bool cmpp(node x, node y) { return x.id < y.id; }
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i].num, a[i].id = i;
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= n; i++)
    if (a[i].num != a[n].num)
      a[i].max = a[n].num;
    else
      a[i].max = a[n - 1].num;
  sort(a + 1, a + n + 1, cmpp);
  for (int i = 1; i <= n; i++) cout << a[i].max << '\n';
  return 0;
}
