// abc134_c.cpp
#include <iostream>
#include <vector>

using namespace std;
int A[200000];
int N;
int main() {
	cin >> N;
	for (int i =0; i<N; i++){
		int a;
		cin >> a;
		A[i] = a;
	}

	int firstMax, secondMax;

	firstMax = 0;
	firstMin = 0;
	
	for ( int i = 1; i< N; i++){
		if (A[firstMax] < A[i]){
			firstMax = i;
		}
		if (A[firstMin] > A[i]){
			firstMin = i;
		}
	}
	A[firstMax] = A[firstMin];
	
	secondMax = 0;
	for ( int i = 1; i< N; i++){
		if (A[secondMax] < A[i]){
			secondMax = i;
		}
	}
	for(int i =0 ; i<N; i++){
		if(i != firstMax){
			cout << A[firstMax] << endl;
		}
		else{
			cout << A[secondMax] << endl;
		}
	}

	return 0;
}