/* Authors: Vu Hoang Bach from Phuoc Hoa Secondary School */

//#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt")

#include <bits/stdc++.h>
#define ldb long double
//#define double ldb
#define db double
#define unomap unordered_map
#define unoset unordered_set
#define endl '\n'
#define str string
#define strstr stringstream
#define sz(a) (int)a.size()
#define ll long long
//#define int ll
#define pii pair <int, int>
#define pll pair <ll, ll>
#define Unique(a) a.resize(unique(all(a)) - a.begin())
#define ull unsigned ll
#define fir first
#define sec second
#define idc cin.ignore()
#define lb lower_bound
#define ub upper_bound
#define all(s) s.begin(), s.end()
#define rev reverse
#define sigma ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define skibidi int main
#define rizz signed main
#define gcd __gcd
#define found(a, mp) mp.find(a) != mp.end()
#define pushb push_back
#define popb pop_back
#define pushf push_front
#define popf pop_front
#define mul2x(a, x) a << x
#define div2x(a, x) a >> x
#define lcm(a, b) (a / __gcd(a, b) * b)
#define log_base(x, base) log(x) / log(base)
#define debug clog << "No errors!"; exit(0);
#define forw(i, a, b) for (int i = a; i <= b; ++i)
#define forw2(i, a, b) for (ll i = a; i <= b; ++i)
#define fors(i, a, b) for (int i = a; i >= b; --i)
#define fors2(i, a, b) for (ll i = a; i >= b; --i)
#define pqueue priority_queue
#define sqrt sqrtl
#define want_digit(x) cout << fixed << setprecision(x);
#define excuting_time 1000.0 * clock() / CLOCKS_PER_SEC
using namespace std;
const int MOD = 1e9 + 7; // 998244353
const int inf = 1e9;
const ll INF = 1e18;
const int N = 1e5;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll random(const ll &L, const ll &R)
{
    return uniform_int_distribution<ll> (L, R) (rng);
}

int n, l, r;
ll a[N + 5], ans;

void recur(int l, int r, int chosen, ll sum)
{
    if (chosen == 3)
    {
        ans = max(ans, sum);
        return;
    }

    forw (i, 0, 3)
    {
        ll add = 1;
        int lef = i, rig = 3 - i;
        forw (j, l, l + lef - 1) add *= a[j];
        forw (j, r - rig + 1, r) add *= a[j];

        recur(l + lef, r - rig, chosen + 1, sum + add);
    }
}

void cook()
{
    cin >> n;
    forw (i, 1, n) cin >> a[i];
    sort(a + 1, a + n + 1);

    ans = -INF;
    recur(1, n, 0, 0);
    cout << ans << endl;
}

skibidi()
//rizz()
{
    srand(time(NULL));
    sigma;
    #define name "test"
    /*
    if (fopen(name".INP", "r"))
    {
        freopen(name".INP", "r", stdin);
        freopen(name".OUT", "w", stdout);
    }
    */
    int numTest = 1;
//    cin >> numTest;
    while (numTest--)
    {
        cook();
    }
    return 0;
}
