Problem: Example

Input

4
5
8
58
85


Output

2970.000000000

Solution (in CPP):

Solution:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
using ld = long double;
constexpr ld PI = 3.14159265358979;
int main()
{
    int N;
    cin >> N;
    vector<ld> r(N);
    for (int i = 0; i < N; i++) {
        cin >> r[i];
    }
    sort(r.begin(), r.end(), greater<ld>{});
    ld maximum = 0;
    for (int i = 3; i <= N; i++) {
        vector<ld> v = r;
        do {
            vector<ld> prod(i);
            for (int j = 0; j < i; j++) {
                prod[j] = v[j] * v[(j + 1) % i];
            }
            sort(prod.begin(), prod.end());
            ld inf = -1;
            ld sup = 1;
            for (int j = 0; j < 30; j++) {
                const ld mid = (inf + sup) / 2;
                const ld lambda = mid * prod[0];
                ld sum = 0;
                for (int k = 0; k < i; k++) {
                    sum += acos(lambda / prod[k]);
                }
                if (sum < 2 * PI) {
                    sup = mid;
                } else {
                    inf = mid;
                }
            }
            inf *= prod[0];
            ld sum = 0;
            ld s = 0;
            for (int j = 0; j < i; j++) {
                const ld theta = acos(inf / prod[j]);
                s += theta;
                sum += prod[j] * sin(theta) / 2;
            }
            if (abs(s - 2 * PI) > 0.001) {
                continue;
            }
            maximum = max(maximum, sum);
        } while (prev_permutation(v.begin(), v.end()));
    }
    cout << fixed << setprecision(15) << maximum << endl;

    return 0;
}