Problem: Example

Input

4
5
8
58
85


Output

2970.000000000

Solution (in CPP):

Solution:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define FIR first
#define SEC second
#define ll long long
#define db double
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
#include <assert.h>
const db eps=1e-10,Pi=acos(-1.0);
int sgn(db x) { return x<-eps?-1:(x>eps); }
db R[20],a[20];
int n;
db calc(db x) {
    a[0]=x; db tot=x;
    for(int i=1;i<n;++i) {
        if(R[i-1]*cos(a[i-1])-eps>R[i+1]) return 0;
        a[i]=acos(R[i-1]*cos(a[i-1])/R[i+1]);
        tot+=a[i];
    }
    return tot;
}
db ans=0,r[20];
void work(int *p) {
    for(int i=0;i<=n;++i) R[i]=r[p[i%n]];
    db lb=0,rb=Pi;
    for(int tt=0;tt<50;++tt) {
        db mid=(lb+rb)/2;
        int tmp=sgn(calc(mid)-2*Pi);
        if(tmp==0) {
            db sum=0;
            for(int i=0;i<n;++i)
                sum+=R[i]*R[i+1]*sin(a[i]);
            ans=max(ans,sum/2);
            return;
        }
        if(tmp>0) rb=mid;
        else lb=mid;
    }
    return;
}
int p[20],m;
int vis[20];
void dfs(int u) {
    if(u>=3) n=u,work(p);
    for(int i=0;i<m;++i) if(!vis[i]) {
        vis[i]=1,p[u]=i,dfs(u+1);
        vis[i]=0;
    }
}
int main() {
    rd(m);
    for(int i=0;i<m;++i) scanf("%lf",&r[i]);
    dfs(0);
    printf("%.9lf",ans);
    return 0;
}