#include <bits/stdc++.h>

using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	for(int &x : a) scanf("%d", &x);
	int mx = -1, smx = -1;
	for(int x : a) {
		if(x > mx) swap(x, mx);
		if(x >smx) swap(x,smx);
	}
	for(int x : a) {
		printf("%d\n", x == mx ? smx : mx);
	}
}
