#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long cc;

cc N, K, Ans, i, j, k, a[5000000], sub = 0;
cc kai[35], A[5000000];

string S;


int main() {
	
	cin >> N;
	for (i = 0; i < N; i++)
		cin >> a[i];

	for (i = 0; i < N; i++) {
		if (A[0] < a[i])
			A[0] = a[i];
		else if (A[1] < a[i])
			A[1] = a[i];
	}
	
	for (i = 0; i < N; i++) {
		if (a[i] != A[0])
			cout << A[0] << endl;
		else
			cout << A[1] << endl;
	}
	return 0;