#include <iostream>
#include <algorithm>
using namespace std;
signed main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
long long n, mx1 = -1e10, mx2 = -1e10, mx3 = -1e10, mn1 = 1e10, mn2 = 1e10;
cin >> n;
for(int i = 0; i < n; i++){
long long x;
cin >> x;
if(x > mx1){
mx3 = mx2;
mx2 = mx1;
mx1 = x;
}
else if(x > mx2){
mx2 = x;
else if(x > mx3)
mx3 = x;
if(x < mn1){
mn2 = mn1;
mn1 = x;
else if(x < mn2)
mn2 = x;
cout << max(mx1 * mx2 * mx3, mn1 * mn2 * mx1);
#include <iostream>
#include <algorithm>
using namespace std;
signed main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
long long n, mx1 = -1e10, mx2 = -1e10, mx3 = -1e10, mn1 = 1e10, mn2 = 1e10;
cin >> n;
for(int i = 0; i < n; i++){
long long x;
cin >> x;
if(x > mx1){
mx3 = mx2;
mx2 = mx1;
mx1 = x;
}
else if(x > mx2){
mx3 = mx2;
mx2 = x;
}
else if(x > mx3)
mx3 = x;
if(x < mn1){
mn2 = mn1;
mn1 = x;
}
else if(x < mn2)
mn2 = x;
}
cout << max(mx1 * mx2 * mx3, mn1 * mn2 * mx1);
}