Problem: Example

Input

4
5
8
58
85


Output

2970.000000000

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;

using dbl=double;
const dbl PI=acos(-1);
const int LOOP=50;

dbl calcAns(dbl theta,int n,vector<dbl>& r){
    dbl sum=0;
    dbl v=cos(theta);
    for(int i=0;i<n;i++){
        dbl tmp=sin(acos(v));
        sum+=0.5*r[i]*r[(i+1)%n]*tmp;
        v=v*r[i]/r[(i+2)%n];
    }
    return sum;
}
dbl calcThetaSum(dbl theta,int n,vector<dbl>& r){
    dbl v=cos(theta);
    dbl sum=0;
    // cerr<<"$$$$$$$$$$"<<endl;
    for(int i=0;i<n;i++){
        dbl tmp=acos(v);
        // cerr<<tmp<<endl;
        if(::isnan(tmp)){
            if(v<0) return 3*PI;
            else return 0;
        }
        sum+=tmp;
        v=v*r[i%n]/r[(i+2)%n];
    }
    return sum;
}
dbl solve(int n,vector<dbl> r){
    dbl lb=0;
    dbl ub=PI;
    if(calcThetaSum(PI,n,r)<2*PI) return 0;
    if(calcThetaSum(0,n,r)>2*PI) return 0;
    for(int i=0;i<LOOP;i++){
        dbl mid=0.5*(lb+ub);
        if(calcThetaSum(mid,n,r)<2*PI) lb=mid;
        else ub=mid;
    }
    // cerr<<"#"<<lb<<" "<<2*PI/6<<endl;
    // cerr<<calcThetaSum(lb,n,r)<<endl;
    // cerr<<calcAns(lb,n,r)<<endl;
    return calcAns(lb,n,r);
}
int main(){
    int n;
    cin>>n;
    vector<dbl> r(n);
    for(int i=0;i<n;i++) cin>>r[i];
    vector<int> ids(n);
    iota(ids.begin(),ids.end(),0);
    dbl res=0;
    do{
        for(int i=3;i<=n;i++){
            vector<dbl> rtmp(i);
            for(int j=0;j<i;j++){
                // cerr<<ids[j]<<" ";
                rtmp[j]=r[ids[j]];
            }
            // cerr<<endl;
            res=max(res,solve(i,rtmp));
        }
    }while(next_permutation(ids.begin(),ids.end()));
    cout<<fixed<<setprecision(10);
    cout<<res<<endl;
    return 0;
}