#include <iostream>
#include <stdlib.h>
using namespace std;
int n;
int niz[100000000];
int i = 0;
int temp;
int main()
{
    int max = -100;
	cin >> n;
	if (n < 2)
		return 0;
	for (i = 0; i < n; i++)
	{
		cin >> niz[i];
		if (niz[0] == 0)
			break;
	}
	
	for (i = 0; i < n; i++)
	{
		if (niz[i] >max)
			max = niz[i];
	}
	
	for (i = 0; i < n; i++)
	{
		if (niz[i] == max)
		{
			temp = niz[0];
			niz[0] = max;
			niz[i] = temp;
		}
	}
	for (i = 0; i < n; i++)
	{
		cout << niz[i]<< " ";
	}
	system("pause");
	return 0;
}