#include <iostream>
#include<string.h>
#include<vector>
using namespace std;

#define rpt(i, n) for(i = 0; i < (n); i++)
typedef long long ll;

int main(void) {
	ll n, a[2 * 10 ^ 5], maxnum, max, maxs, i;

	cin >> n;
	rpt(i, n) {
		cin >> a[i];
	}

	max = a[0];
	maxnum = 0;
	rpt(i, n) {
		if (max < a[i]) {
			max = a[i];
			maxnum = i;
		}
	}
	a[maxnum] = 0;

	maxs = a[0];
	rpt(i, n) {
		if (maxs < a[i]) {
			maxs = a[i];
		}
	}
	

	rpt(i, n) {
		if (maxnum == i) {
			cout << maxs << endl;
		}
		else {
			cout << max << endl;
		}
	}

	return 0;
}