Problem: Example

Input

4
5
8
58
85


Output

2970.000000000

Solution (in CPP):

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

using namespace std;

const double PI=3.14159265358979323846264;

int N;
int r[8];
bool used[8];

int r2[8];
int c[8];
int M;
double solve(){
	for(int i=0;i<M;i++){
		if(i!=M-1) c[i]=r2[i]*r2[i+1];
		else c[i]=r2[i]*r2[0];
	}
	double lb=0,ub=PI;
	double theta[8];
	for(int stage=0;stage<100;stage++){
		double mid=(ub+lb)/2;
		double sum=0;
		double cos1=cos(mid);
		double lambda=cos1*c[0];
		sum+=mid;
		theta[0]=mid;
		bool ok=true;
		for(int i=1;i<M;i++){
			double ccos=lambda/c[i];
			if(abs(ccos)>1){
				ok=false;
				break;
			}
			double theta_=acos(ccos);
			sum+=theta_;
			theta[i]=theta_;
		}
		if(ok==false){
			if(mid>PI/2) ub=mid;
			else lb=mid;
			continue;
		}
		if(sum>PI*2){
			ub=mid;
		}else{
			lb=mid;
		}
	}
	
	double sum=0;
	for(int i=0;i<M;i++) sum+=theta[i];
	if(abs(sum-PI*2)>1e-9) return -1;
	double cos1=cos(lb);
	double res=0;
	for(int i=0;i<M;i++){
		res+=sin(theta[i])*c[i];
	}
	return res;
}

double ans=0;

void dfs(int num){
	if(num>=3){
		M=num;
		double tmp=solve();
		ans=max(ans,tmp);
	}
	if(num==N) return;
	for(int i=0;i<N;i++){
		if(used[i]==false){
			used[i]=true;
			r2[num]=r[i];
			dfs(num+1);
			used[i]=false;
		}
	}
}

int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",r+i);
	}
	dfs(0);
	printf("%.9f\n",ans/2);
	return 0;
}