Problem: Example

Input

4
5
8
58
85


Output

2970.000000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double l[8];

double f(double v,vector<double> L){
	double sum = 0;
	for(int i = 0 ; i < L.size() - 1 ; i++){
		double t = v / L[i] / L[i+1];
		sum += acos(t);	
	}
	return sum;
}
double calc(double v,vector<double> L){
	double sum = 0;
	for(int i = 0 ; i < L.size() - 1 ; i++){
		double t = v / L[i] / L[i+1];
		
		sum += sin(acos(t)) * L[i] * L[i+1] / 2.0;
	}
	return sum;
}
int main(){
	int N;
	cin >> N;
	for(int i = 0 ; i < N ; i++) cin >> l[i];
	
	double ans = 0;
	for(int i = 0 ; i < (1<<N) ; i++){
		vector<double> L;
		for(int j = 0 ; j < N ; j++)
			if( i >> j & 1 ) L.push_back(l[j]);
		if( L.size() < 3 ) continue;
		
		sort(L.begin(),L.end());
		do{
			L.push_back(L.front());
			double s = 1e18;
			for(int j = 0 ; j < L.size() - 1 ; j++)
				s = min(s,L[j] * L[j+1]);
			double le = -2*s , ri = 2*s;
			for(int k = 0 ; k < 128 ; k++){
				double mi = (le+ri) / 2.;
				if( f(mi,L) < 2 * PI ){
					ri = mi;
				}else{
					le = mi;
				}
			}
			//cout << f(le,L) << endl;
			ans = max(ans,calc(le,L));
			L.pop_back();
		}while(next_permutation(L.begin(),L.end()));
	}
	printf("%.15lf\n",ans);
}