Problem: Example

Input

4
5
8
58
85


Output

2970.000000000

Solution (in CPP):

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

using ld = long double;

const ld pi = acos(-1.0);
constexpr ld eps = 1e-9;

int main() {
    int n; cin >> n;
    vector<ld> rr(n);
    for(int i = 0; i < n; ++i) {
        cin >> rr[i];
    }
    sort(begin(rr), end(rr));

    ld ans = 0;
    for(int S = 1; S < (1 << n); ++S) {
        vector<ld> r;
        for(int i = 0; i < n; ++i) {
            if(S & (1 << i)) {
                r.push_back(rr[i]);
            }
        }
        const int m = r.size();
        if(m < 3) continue;
        do {
            ld tans = 0, ang_sum = 0;
            auto check = [&] (ld theta) {
                ang_sum = theta;
                tans = 0.5 * r[0] * r[1] * sin(theta);
                for(int i = 1; i < m; ++i) {
                    const auto ang = acos(max(-1.0L, min(1.0L, r[0] * r[1] / r[i] / r[(i + 1) % m] * cos(theta))));
                    tans += 0.5 * r[i] * r[(i + 1) % m] * sin(ang);
                    ang_sum += ang;
                }
                return ang_sum < 2 * pi;
            };
            ld lb = 0, ub = pi;
            for(int lp = 0; lp < 100; ++lp) {
                const auto mid = (lb + ub) / 2;
                (check(mid) ? lb : ub) = mid;
            }
            if(abs(ang_sum - 2 * pi) < eps) {
                ans = max(ans, tans);
            }
        } while(next_permutation(begin(r) + 1, end(r)));
    }
    cout << fixed << setprecision(10) << ans << endl;
}