#include<iostream>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
int n;
int a[200001];
int x=0;
int main(){
	ios::sync_with_stdio(false);
   cin.tie(NULL); cout.tie(NULL);
   cin >> N;
   for (int i = 0; i < N; i ++) cin >> A[i];
   for (int i = 0; i < N; i ++) B[i] = A[i];
	sort(A, A + N); reverse(A, A + N);
	for (int i = 0; i < N; i ++) 
	{
		if (B[i] == A[0]) cout << A[1];
		else cout << A[0];
		cout << endl;
	}
   return 0;
}

system ("pause");
return 0;
}
