
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	int N;
	cin >>N;
	vector <int> A(N);

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

	int max;
	int second_max;

	
	vector <int> B(N);
	copy(A.begin(), A.end(), back_inserter(B));

	sort(B.begin(), B.end(), greater<int>);
	max = B[0];
	second_max = B[1];

	for (int i = 0; i < N; i++) {
		if (A[i]==max) {
			cout << second_max << endl;
		}
		else {
			cout << max << endl;
		}
	}
}