#include <bits/stdc++.h>
using namespace std;

int main(){
	int N;
		cin >> N;
		int A[N];
		int m1=0,m2=0,n1;
		for(int i=0;i<N;i++){
			cin >> A[i];
			if(m1 < A[i]){m2=m1;m1=A[i];n1=i;}
			else if(m2 < A[i]) m2=A[i];
		}
		for(int i=0;i<N;i++){
			if(i != n1) cout << m1 << endl;
			else cout << m2 << endl;
		}
	return 0;
}

