Problem: Example

Input

4
5
8
58
85


Output

2970.000000000

Solution (in CPP):

Solution:
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
double pi=3.14159265358979;
int m;
vector<int> r;
double ans;
bool check(double mid){
	double p[8]={},cop[8]={},sum=0;
	p[0]=mid;
	cop[0]=cos(p[0]);
	sum=p[0];
	rep1(i,m-1){
		cop[i]=cop[i-1]/r[(i+1)%m]*r[i-1];
		if(abs(cop[i])>1) return false;
		p[i]=acos(cop[i]);
		sum+=p[i];
	}
	if(sum>2*pi) return false;
	return true;
}
void update(double mid){
	double p[8]={},cop[8]={},sum=0;
	p[0]=mid;
	cop[0]=cos(p[0]);
	sum=p[0];
	rep1(i,m-1){
		cop[i]=cop[i-1]/r[(i+1)%m]*r[i-1];
		if(abs(cop[i])>1) return;
		p[i]=acos(cop[i]);
		sum+=p[i];
	}
	if(sum>2*pi) return;
	double tmp=0;
	rep(i,m){
		tmp+=r[i]*r[(i+1)%m]*sin(p[i])/2;
	}
	ans=max(ans,tmp);
}
int main(){
	int N;
	cin>>N;
	rep(i,N){
		int ri;
		cin>>ri;
		r.pb(ri);
	}
	while(r.size()>=3){
		sort(all(r));
		m=r.size();
		do{
			double ub=pi,lb=0;
			int cnt=0;
			while(cnt<100){
				double mid=(ub+lb)/2;
				if(check(mid)) lb=mid;
				else ub=mid;
				cnt++;
			}
			update(lb);
		}while(next_permutation(r.begin(),r.end()));
		sort(all(r),greater<int>());
		r.erase(r.end()-1);
	}
	printf("%.12f\n",ans);
}