Problem: Example

Input

4
5
8
58
85


Output

2970.000000000

Solution (in CPP):

Solution:
#include "bits/stdc++.h"
 
using namespace std;
 
using ld = double;
const ld eps = 1e-9, pi = acos(-1.0);
 
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    int n;
    cin >> n;
    vector<ld> rr(n);
    for (int i = 0; i < n; i++)
        cin >> rr[i];
    sort(rr.begin(), rr.end());
    ld ret = 0;
    for (int b = 1; b < (1 << n); b++)
    {
        vector<ld> r;
        for (int i = 0; i < n; i++)
        {
            if ((b >> i) & 1)
                r.push_back(rr[i]);
        }
        int sz = r.size();
        if (sz < 3)
            continue;
        do
        {
            //
            ld lb = 0, ub = pi, ar = 0, sum = 0;
            for (int i = 0; i < 100; i++)
            {
                auto mid = (lb + ub) / 2;
                sum = 0;
                ar = 0;
                for (int j = 0; j < sz; j++)
                {
                    auto tmp = acos(max((ld)-1.0, min((ld)1.0, r[0] * r[1] / r[j] / r[(j + 1) % sz] * cos(mid))));
                    ar += 0.5 * r[j] * r[(j + 1) % sz] * sin(tmp);
                    sum += tmp;
                }
                if (sum < 2 * pi)
                    lb = mid;
                else
                    ub = mid;
            }
            if (abs(sum - 2 * pi) < eps)
                ret = max(ret, ar);
        } while (next_permutation(r.begin() + 1, r.end()));
    }
    cout << fixed << setprecision(10) << ret << endl;
}