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

int main(void) {
	int n;
	cin >> n;
	vector<int> a(n);
	
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	vector<int> b = a;
	sort(b.rbegin(), b.rend());
	for (int i = 0; i < n; i++){
		int ans = b[0];
		if (a[i] == b[0]) ans = b[1]; 
		cout << ans << endl;
	}
	return 0;
}
