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

int N, A[1 << 18], B[1 << 18];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) { cin >> A[i]; B[i] = A[i]; }
	sort(B, B + N);
	for (int i = 0; i < N; i++) {
		if (A[i] == B[N - 1]) cout << B[N - 2] << endl;
		else cout << B[N - 1] << endl;
	}
	return 0;
}