#include <bits/stdc++.h>
using namespace std;

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

	sort(B.begin(), B.end());
	for (int i = 0; i < N; i++) {
		if (A[i] != B[N - 1]) cout << B[N - 1] << endl;
		else cout << B[N - 2] << endl;
	}
}