Problem: Example

Input

4
5
8
58
85


Output

2970.000000000

Solution (in CPP):

Solution:
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
double b[10];
int perm[10];
double PI=acos(-1.0);
double EPS=1e-9;
double solve(int a){
	double left=0;
	double right=PI;
	for(int i=0;i<100;i++){
		double M=(left+right)/2;
		double th=M;
		double val=M;
		for(int j=0;j<a-1;j++){
			if(b[perm[(j+a-1)%a]]*cos(th)>b[perm[j+1]]){val=0;break;}
			double L=acos(b[perm[(j+a-1)%a]]*cos(th)/b[perm[j+1]]);
			val+=L;
			th=L;
		}
		if(val>2*PI)right=M;
		else left=M;
	}
	double t=right;
	double s=b[perm[0]]*b[perm[a-1]]*sin(right);
	double now=t;
	for(int i=0;i<a-1;i++){
		if(b[perm[(i+a-1)%a]]*cos(t)>b[perm[i+1]]+EPS)return 0;
		double L=acos(b[perm[(i+a-1)%a]]*cos(t)/b[perm[i+1]]);
		t=L;
		now+=t;
		s+=b[perm[i]]*b[perm[i+1]]*sin(t);
	}
	if(now>2*PI+EPS)return 0;
	/*if(s/2>800000){
		for(int i=0;i<a;i++)printf("%d ",perm[i]);
		printf(", %f %f\n",right,s/2);
		printf("\n");
	}*/
	return s/2;
}
int v[10];
int n;
double dfs(int a){
	double ret=0;
	if(a>=3)ret=max(ret,solve(a));
	if(a<n){
		for(int i=0;i<n;i++){
			if(v[i])continue;
			v[i]=1;
			perm[a]=i;
			ret=max(ret,dfs(a+1));
			v[i]=0;
		}
	}
	return ret;
}
int main(){
	int a;
	scanf("%d",&a);
	n=a;
	for(int i=0;i<a;i++)scanf("%lf",b+i);	
	printf("%.12f\n",dfs(0));
}