#include <iostream>
#include <vector>
using namespace std;

int main () {
	int N;
	int max=0, sucmax=0, maxid=-1;
	cin >> N;
	for (int i=0; i<N; i++) {
		int tmp;
		cin >> tmp;
		if (tmp>=max) {
			sucmax = max;
			max = tmp;
			maxid = i;
		} else if (tmp>sucmax) {
			sucmax = tmp;
		}
	}
	for (int i=0; i<N; i++) {
		if (i==maxid)
			cout << sucmax << endl;
		else
			cout << max << endl;
	}
	return 0;
}
#include <iostream>
#include <vector>
using namespace std;

int main () {
	int N;
	int max=0, sucmax=0, maxid=-1;
	cin >> N;
	for (int i=0; i<N; i++) {
		int tmp;
		cin >> tmp;
		if (tmp>=max) {
			sucmax = max;
			max = tmp;
			maxid = i;
		} else if (tmp>sucmax) {
			sucmax = tmp;
		}
	}
	for (int i=0; i<N; i++) {
		if (i==maxid)
			cout << sucmax << endl;
		else
			cout << max << endl;
	}
	return 0;
}