#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define MOD 1000000007
#define FOR(i,a,b) for (int i = (a);i <= (b);i++)
#define FOD(i,a,b) for (int i = (b);i >= (a);i--)
#define ALL(x) (x).begin(),(x).end()
#define ii pair<ll,ll>
#define iii pair<int,pair<int,int>>
//const int MOD = 998244353;
const int MAXN = 1e5 + 7;
const int maxn = 1687;
const ll oo = 9e18;
int a[MAXN],n,m = 1;
vector<ll> v,premu[maxn],tmp;
bool f[19];
ll ans = -oo;
void cre(int id){
if (!id){
for (auto x : tmp)premu[m].push_back(x);
m++;
return ;
}
FOR(i,1,9)if (!f[i]){
f[i] = true;tmp.push_back(i);
FOR(j,i + 1,9)if (!f[j]){
f[j] = true;tmp.push_back(j);
FOR(k,j + 1,9)if (!f[k]){
f[k] = true;tmp.push_back(k);
cre(id - 1);f[k] = false;tmp.pop_back();
}
f[j] = false;tmp.pop_back();
}
f[i] = false;tmp.pop_back();
}
}
ll check(){
ll ans = -oo;
FOR(i,1,m - 1){
ll res = 0;
for (int j = 0;j < 9;j += 3)
res = res + v[premu[i][j]] * v[premu[i][j + 1]] * v[premu[i][j + 2]];
ans = max(ans,res);
}
return ans;
}
void sub1(int mask = n){
cre(3);
FOR(i,1,(1<<mask) - 1)
if (__builtin_popcount(i) == 9){
v.clear();v.push_back(0);
FOR(j,0,mask - 1)if (i >> j & 1)
v.push_back(a[j + 1]);
ans = max(ans,check());
}
cout << ans;
}
void sub2(){
sort(a+1,a+1+n);
FOR(i,10,18)a[i] = a[n - i + 10];
n = 18;sub1();
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
FOR(i,1,n)cin >> a[i];
if (n <= 18)sub1();
else sub2();
return 0^0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBz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wLnBvcF9iYWNrKCk7CiAgICAgICAgfQogICAgICAgIGZbaV0gPSBmYWxzZTt0bXAucG9wX2JhY2soKTsKICAgIH0KfQpsbCBjaGVjaygpewogICAgbGwgYW5zID0gLW9vOwogICAgRk9SKGksMSxtIC0gMSl7CiAgICAgICAgbGwgcmVzID0gMDsKICAgICAgICBmb3IgKGludCBqID0gMDtqIDwgOTtqICs9IDMpCiAgICAgICAgcmVzID0gcmVzICsgdltwcmVtdVtpXVtqXV0gKiB2W3ByZW11W2ldW2ogKyAxXV0gKiB2W3ByZW11W2ldW2ogKyAyXV07CiAgICAgICAgYW5zID0gbWF4KGFucyxyZXMpOwogICAgfQogICAgcmV0dXJuIGFuczsKfQp2b2lkIHN1YjEoaW50IG1hc2sgPSBuKXsKICAgIGNyZSgzKTsKICAgIEZPUihpLDEsKDE8PG1hc2spIC0gMSkKICAgIGlmIChfX2J1aWx0aW5fcG9wY291bnQoaSkgPT0gOSl7CiAgICAgICAgdi5jbGVhcigpO3YucHVzaF9iYWNrKDApOwogICAgICAgIEZPUihqLDAsbWFzayAtIDEpaWYgKGkgPj4gaiAmIDEpCiAgICAgICAgdi5wdXNoX2JhY2soYVtqICsgMV0pOwogICAgICAgIGFucyA9IG1heChhbnMsY2hlY2soKSk7CiAgICB9CiAgICBjb3V0IDw8IGFuczsKfQp2b2lkIHN1YjIoKXsKICAgIHNvcnQoYSsxLGErMStuKTsKICAgIEZPUihpLDEwLDE4KWFbaV0gPSBhW24gLSBpICsgMTBdOwogICAgbiA9IDE4O3N1YjEoKTsKfQppbnQgbWFpbigpewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKDApOyBjb3V0LnRpZSgwKTsKICAgIGNpbiA+PiBuOwogICAgRk9SKGksMSxuKWNpbiA+PiBhW2ldOwogICAgaWYgKG4gPD0gMTgpc3ViMSgpOwogICAgZWxzZSBzdWIyKCk7CiAgICByZXR1cm4gMF4wOwp9Cg==