#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

int main(){
	int i, n;
	cin >> n;
	int a[n];

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

	int max = *max_element(a, a + n);
	for(i = 0; i < n; i++){
		if(a[i] == max){
			a[i] = 0;
			cout << *max_element(a, a + n) << endl;
			a[i] = max;
		}else{
			cout << max << endl;
		}
	}

	return 0;
}