Problem: Example

Input

4
5
8
58
85


Output

2970.000000000

Solution (in CPP):

Solution:
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

const double EPS=1e-8;
const double PI=acos(-1);

double solve(const vector<double> &r){
	int n=r.size();
	vector<double> theta(n);

	double lo=0,hi=PI;
	rep(i,n-1){
		double a=(r[n-1]*r[0])/(r[i]*r[(i+1)%n]);
		if(a>1-EPS){
			lo=max(lo,acos( 1/a));
			hi=min(hi,acos(-1/a));
		}
	}
	rep(_,30){
		double mi=(lo+hi)/2;
		theta[n-1]=mi;
		rep(i,n-1){
			double a=(r[n-1]*r[0])/(r[i]*r[(i+1)%n]);
			theta[i]=acos(a*cos(theta[n-1]));
		}

		double sum=0;
		rep(i,n) sum+=theta[i];

		if(sum<2*PI) lo=mi; else hi=mi;
	}

	double area=0;
	rep(i,n) area+=r[i]*r[(i+1)%n]*sin(theta[i]);
	area/=2;
	return area;
}

int main(){
	int n; scanf("%d",&n);
	int r[8];
	rep(i,n) scanf("%d",r+i);

	double ans=0;
	rep(S,1<<n){
		vector<double> a;
		rep(i,n) if(S>>i&1) a.push_back(r[i]);
		if(a.size()<3) continue;

		sort(a.begin(),a.end());
		do{
			ans=max(ans,solve(a));
		}while(next_permutation(a.begin(),a.end()));
	}
	printf("%.9f\n",ans);

	return 0;
}