#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 ll oo = 9e18;
int a[MAXN],n;
vector<ll> v;
bool f[19];
ll ans = -oo;
void check(int id,ll cur){
if (!id){
ans = max(ans,cur);
return ;
}
FOR(i,1,9)if (!f[i]){
f[i] = true;
FOR(j,1,9)if (!f[j]){
f[j] = true;
FOR(k,1,9)if (!f[k]){
f[k] = true;
check(id - 1,cur + v[i] * v[j] * v[k]);
f[k] = false;
}
f[j] = false;
}
f[i] = false;
}
}
void sub1(int mask = n){
int cnt = 0;
FOR(i,1,(1<<mask) - 1)
if (__builtin_popcount(i) == 9){
cnt++;
v.clear();v.push_back(0);
FOR(j,0,mask - 1)if (i >> j & 1)
v.push_back(a[j + 1]);
check(3,0);
}
cout << ans;
}
void sub2(){
}
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+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBNT0QgMTAwMDAwMDAwNwojZGVmaW5lIEZPUihpLGEsYikgZm9yIChpbnQgaSA9IChhKTtpIDw9IChiKTtpKyspCiNkZWZpbmUgRk9EKGksYSxiKSBmb3IgKGludCBpID0gKGIpO2kgPj0gKGEpO2ktLSkKI2RlZmluZSBBTEwoeCkgKHgpLmJlZ2luKCksKHgpLmVuZCgpCiNkZWZpbmUgaWkgcGFpcjxsbCxsbD4KI2RlZmluZSBpaWkgcGFpcjxpbnQscGFpcjxpbnQsaW50Pj4KLy9jb25zdCBpbnQgTU9EID0gOTk4MjQ0MzUzOwpjb25zdCBpbnQgTUFYTiA9IDFlNSArIDc7CmNvbnN0IGxsIG9vID0gOWUxODsKaW50IGFbTUFYTl0sbjsKdmVjdG9yPGxsPiB2Owpib29sIGZbMTldOwpsbCBhbnMgPSAtb287CnZvaWQgY2hlY2soaW50IGlkLGxsIGN1cil7CiAgICBpZiAoIWlkKXsKICAgICAgICBhbnMgPSBtYXgoYW5zLGN1cik7CiAgICAgICAgcmV0dXJuIDsKICAgIH0KICAgIEZPUihpLDEsOSlpZiAoIWZbaV0pewogICAgICAgIGZbaV0gPSB0cnVlOwogICAgICAgIEZPUihqLDEsOSlpZiAoIWZbal0pewogICAgICAgICAgICBmW2pdID0gdHJ1ZTsKICAgICAgICAgICAgRk9SKGssMSw5KWlmICghZltrXSl7CiAgICAgICAgICAgICAgICBmW2tdID0gdHJ1ZTsKICAgICAgICAgICAgICAgIGNoZWNrKGlkIC0gMSxjdXIgKyB2W2ldICogdltqXSAqIHZba10pOwogICAgICAgICAgICAgICAgZltrXSA9IGZhbHNlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGZbal0gPSBmYWxzZTsKICAgICAgICB9CiAgICAgICAgZltpXSA9IGZhbHNlOwogICAgfQp9CnZvaWQgc3ViMShpbnQgbWFzayA9IG4pewoJaW50IGNudCA9IDA7CiAgICBGT1IoaSwxLCgxPDxtYXNrKSAtIDEpCiAgICBpZiAoX19idWlsdGluX3BvcGNvdW50KGkpID09IDkpewogICAgCWNudCsrOwogICAgICAgIHYuY2xlYXIoKTt2LnB1c2hfYmFjaygwKTsKICAgICAgICBGT1IoaiwwLG1hc2sgLSAxKWlmIChpID4+IGogJiAxKQogICAgICAgIHYucHVzaF9iYWNrKGFbaiArIDFdKTsKICAgICAgICBjaGVjaygzLDApOwogICAgfQogICAgY291dCA8PCBhbnM7Cn0Kdm9pZCBzdWIyKCl7Cgp9CmludCBtYWluKCl7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUoMCk7IGNvdXQudGllKDApOwogICAgY2luID4+IG47CiAgICBGT1IoaSwxLG4pY2luID4+IGFbaV07CiAgICBpZiAobiA8PSAxOClzdWIxKCk7CiAgICBlbHNlIHN1YjIoKTsKICAgIHJldHVybiAwXjA7Cn0K