#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
// assuming array's length is at least 7
vector<int> a(n); for(int &x:a) cin>>x;
vector<pair<int,int>> P[2];
P[0].resize(n,{0,INT_MAX}); // products on the left
P[1].resize(n,{0,INT_MAX}); // products on the right
// we'll start filling from P[2] because
// first two elements of the array cannot be multiplied.
int mx = a[0],mn = a[0]; // max_element(0,0) and min_element(0,0)
for(int i=2;i<n;i++) {
P[0][i] = P[0][i-1];
P[0][i].first = max(P[0][i].first,a[i]*mx);
P[0][i].second = min(P[0][i].second,a[i]*mn);
mx = max(mx,a[i-1]); mn = min(mn,a[i-1]);
}
// we'll start from P[n-3] because
// last two elements of the arrays cannot be multiplied.
mx = a[n-1],mn = a[n-1]; // max_element(n-1,n-1) and min_element(n-1,n-1)
for(int i=n-3;i>=0;i--){
P[1][i] = P[1][i+1];
P[1][i].first = max(P[1][i].first,a[i]*mx);
P[1][i].second = min(P[1][i].second,a[i]*mn);
mx = max(mx,a[i+1]); mn = min(mn,a[i+1]);
}
int ans = 0;
for(int i=2;i<n-3;i++){
ans = max(ans,max(P[0][i].first-P[0][i+1].second,P[1][i+1].first-P[1][i].second));
}
cout<<ans;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpewogICAgaW50IG47IGNpbj4+bjsKICAgIC8vIGFzc3VtaW5nIGFycmF5J3MgbGVuZ3RoIGlzIGF0IGxlYXN0IDcKICAgIHZlY3RvcjxpbnQ+IGEobik7IGZvcihpbnQgJng6YSkgY2luPj54OwogICAgdmVjdG9yPHBhaXI8aW50LGludD4+IFBbMl07IAogICAgUFswXS5yZXNpemUobix7MCxJTlRfTUFYfSk7IC8vIHByb2R1Y3RzIG9uIHRoZSBsZWZ0IAogICAgUFsxXS5yZXNpemUobix7MCxJTlRfTUFYfSk7IC8vIHByb2R1Y3RzIG9uIHRoZSByaWdodAogICAgLy8gd2UnbGwgc3Rhc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