Problem: Example

Input

4
5
8
58
85


Output

2970.000000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double l[8];
 
double f(double t0,vector<double> L){
    double v = cos(t0) * L[0] * L[1];
    double sum = 0;
    for(int i = 0 ; i < L.size() - 1 ; i++){
        double X = v / L[i] / L[i+1];
        sum += acos(X);
    }
    // cout << sum << endl;
    return sum;
}
double calc(double t0,vector<double> L){
    double v = cos(t0) * L[0] * L[1];
    double sum = 0;
    for(int i = 0 ; i < L.size() - 1 ; i++){
        double X = v / L[i] / L[i+1];
        sum += sin(acos(X)) * L[i] * L[i+1] / 2.0;
    }
    return sum;
}
int main(){
    int N;
    cin >> N;
    for(int i = 0 ; i < N ; i++) cin >> l[i];
     
    double ans = 0;
    for(int i = 0 ; i < (1<<N) ; i++){
        vector<double> L;
        for(int j = 0 ; j < N ; j++)
            if( i >> j & 1 ) L.push_back(l[j]);
        if( L.size() < 3 ) continue;
        sort(L.begin(),L.end());
        do{
            L.push_back(L.front());
             
            double le = 0 , ri = PI;
            for(int k = 0 ; k < 128 ; k++){
                double mi = (le+ri) / 2.;
                if( f(mi,L) > 2 * PI ){
                    ri = mi;
                }else{
                    le = mi;
                }
            }
            if( fabs(f(le,L)-2*PI)  < 1e-9 )
				ans = max(ans,calc(le,L));
            L.pop_back();
        }while(next_permutation(L.begin()+1,L.end()));
        // cout << L.size() << "|" <<  f(2*PI/6,L) << endl;
    }
    printf("%.15lf\n",ans);
}