#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < n; i++)
const int INF = 1001001001;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<int> b = a;
	sort(b.begin(), b.end());
	int first = b[n - 1], second = b[n-2];
	rep(i, n) {
		int now = a[i];
		if (now == first) cout << second << endl;
		else cout << first << endl;
	}
	return 0;
}