#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef std::pair<int,int> sp;
bool spc(sp one,sp two)
{
	return one.first*one.second<two.first*two.second;
}
void check(int &lhs,int &rhs,int cur,int a1,int min)
{
	sp tmp1=sp(lhs,rhs);
	sp tmp2=sp(lhs,cur);
	sp tmp3=sp(a1,cur);
	sp tmp4=sp(min,cur);
	std::vector<sp> res;
	res.push_back(tmp1);res.push_back(tmp2);res.push_back(tmp3);
	res.push_back(tmp4);
	std::sort(res.begin(),res.end(),spc);
	lhs=res[0].first;rhs=res[0].second;
}
int main()
{
	int lhs=1000,rhs=1000,a1=0,a2=0,a3=0,a4=0,a5=0,a6=0,m=0,cur=0;
	int N;
	cin>>N;
	int i=0;
	for(i;i<6;i++)
	{
		
		a1=a2;
		a2=a3;
		a3=a4;
		a4=a5;
		a5=a6;
		cin>>cur;
		a6=cur;
	}
	m=a1;
	for(i;i<N;i++)
	{
		cin>>cur;
		check(lhs,rhs,cur,a1,m);
		m=std::min(m,a1);
		a1=a2;
		a2=a3;
		a3=a4;
		a4=a5;
		a5=a6;
		a6=cur;
	}
	cout<<endl<<endl;
	cout<<lhs*rhs;
	return 0;
}