#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 200005
using namespace std;

int n, a[N], b[N];
int main() {
	int i;
	cin >> n;
	for(i=0; i<n; i++) scanf("%d", &a[i]), b[i] = a[i];
	sort(b, b+n);
	for(i=0; i<n; i++) {
		printf("%d\n", a[i]==b[n-1] ? b[n-2] : b[n-1]);
	}
    return 0;
}