#include <iostream>
#include <valarray>
#include <cstdio>
using namespace std;

int main() {
	int n;
	cin >> n;
	valarray<int> a(n);
	for (int i = 0; i < n; ++i) {
		int d = scanf_s("%d", &a[i]);
	}
	valarray<int> b = a;
	int max1 = b.max();
	valarray<bool> m = b != max1;
	valarray<int> r = b[m];
	int max2 = r.max();
	for (int i = 0; i < n; ++i) {
		if (b[i] == max1) {

			cout << max2 << "\n";
		}
		else {

			cout << max1 << "\n";
		}
	}
}
