#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
const int mx = 200005;
int n, a[mx], ans, m, s;

int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%d", a+i);
		if(a[i]>=m){
			s = m;
			m = a[i];
		}else if(a[i] > s) s = a[i];
	}
	rep(i,n) printf("%d\n",a[i]==m?s:m);
}