#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;
}
