Problem: Example

Input

4
5
8
58
85


Output

2970.000000000

Solution (in CPP):

Solution:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(__typeof__(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}



typedef long double DD;

const DD INF = 1LL<<30;
const DD EPS = 1e-7;
const DD PI = acos(-1.0);
DD torad(int deg) {return (DD)(deg) * PI / 180;}
DD todeg(DD ang) {return ang * 180 / PI;}

struct Point {
    DD x, y;
    Point(DD x = 0.0, DD y = 0.0) : x(x), y(y) {}
    friend ostream& operator << (ostream &s, const Point &p) {return s << '(' << p.x << ", " << p.y << ')';}
};

Point operator + (Point p, Point q) {return Point(p.x + q.x, p.y + q.y);}
Point operator - (Point p, Point q) {return Point(p.x - q.x, p.y - q.y);}
Point operator * (Point p, DD a) {return Point(p.x * a, p.y * a);}
Point operator * (DD a, Point p) {return Point(a * p.x, a * p.y);}
Point operator * (Point p, Point q) {return Point(p.x * q.x - p.y * q.y, p.x * q.y + p.y * q.x);}
Point operator / (Point p, DD a) {return Point(p.x / a, p.y / a);}
Point conj(Point p) {return Point(p.x, -p.y);}
Point rot(Point p, DD ang) {return Point(cos(ang) * p.x - sin(ang) * p.y, sin(ang) * p.x + cos(ang) * p.y);}
Point rot90(Point p) {return Point(-p.y, p.x);}
DD cross(Point p, Point q) {return p.x * q.y - p.y * q.x;}
DD dot(Point p, Point q) {return p.x * q.x + p.y * q.y;}
DD norm(Point p) {return dot(p, p);}
DD abs(Point p) {return sqrt(dot(p, p));}
DD amp(Point p) {DD res = atan2(p.y, p.x); //if (res < 0) res += PI*2; 
    return res;}
bool eq(Point p, Point q) {return abs(p - q) < EPS;}
bool operator < (Point p, Point q) {return (abs(p.x - q.x) > EPS ? p.x < q.x : p.y < q.y);}
bool operator > (Point p, Point q) {return (abs(p.x - q.x) > EPS ? p.x > q.x : p.y > q.y);}
Point operator / (Point p, Point q) {return p * conj(q) / norm(q);}

int ccw(Point a, Point b, Point c) {
    if (cross(b-a, c-a) > EPS) return 1;
    if (cross(b-a, c-a) < -EPS) return -1;
    if (dot(b-a, c-a) < -EPS) return 2;
    if (norm(b-a) < norm(c-a) - EPS) return -2;
    return 0;
    
}

struct Line : vector<Point> {
    Line(Point a = Point(0.0, 0.0), Point b = Point(0.0, 0.0)) {
        this->push_back(a);
        this->push_back(b);
    }
};


struct Circle : Point{
    DD r;
    Circle(Point p = Point(0.0, 0.0), DD r = 0.0) : Point(p), r(r) {}
};

Point proj(Point p, Line l) {
    DD t = dot(p - l[0], l[1] - l[0]) / norm(l[1] - l[0]);
    return l[0] + (l[1] - l[0]) * t;
}
vector<Point> crosspoint(Circle e, Line l) {
    vector<Point> res;
    Point p = proj(e, l);
    DD rcos = abs(e - p);
    if (rcos > e.r + EPS) return vector<Point>();
    DD rsin = sqrt(e.r * e.r - rcos * rcos);
    Point dir = (l[1] - l[0]) / abs(l[1] - l[0]);
    Point p1 = p + dir * rsin;
    Point p2 = p - dir * rsin;
    res.push_back(p1);
    if (!eq(p1, p2)) res.push_back(p2);
    return res;
}



int N;
double ir;
vector<DD> r, rr, prr, inst;
vector<Point> pol;
Point ori(0.0, 0.0);
DD med, sum, area;

pair<bool, DD> isexceed(Point ip, Point sp) {
    //if (r[0] == 8 && r[1] == 85) {cout << endl << endl; COUT(med);}
    
    sum = amp(sp / ip);
    area = ir * r[0] * sin(sum) / 2;
    for (int i = 1; i < r.size(); ++i) {
        Line h(ip, proj(ip, Line(ori, sp)));
        Circle c(ori, r[i]);
        vector<Point> temp = crosspoint(c, h);
        
        if (temp.size() == 0) {
            //cout << "here" <<endl;
            if (amp(pol[pol.size()-1]/pol[pol.size()-2]) < torad(90)) return MP(false, -1);
            else return MP(true, -1);
        }
        
        Point np;
        DD ang = -INF;
        for (int j = 0; j < temp.size(); ++j) {
            DD tang = amp(temp[j] / sp);
            if (tang > ang) {
                ang = tang;
                np = temp[j];
            }
        }
        ip = sp;
        sp = np;
        pol.PB(np);
        sum += ang;
        area += r[i-1] * r[i] * sin(ang) / 2;
        
        if (r[0] == 8 && r[1] == 85) {
            //cout << i << " : " << pol; COUT(med); COUT(temp); COUT(ang); COUT(sum); COUT(area); cout << endl;
        }
    }
    
    return MP((sum > torad(360)), area);
}

int main() {
    //freopen( "/Users/macuser/Documents/Programming/Contest/input.in", "r", stdin );
    
    while (cin >> N) {
        inst.resize(N, 0.0);
        for (int i = 0; i < N; ++i) {
            cin >> inst[i];
        }
        sort(ALL(inst));
        
        
        DD res = 0.0;
        for (int bit = 1; bit < (1<<N); ++bit) {
            if (__builtin_popcount(bit) < 3) continue;
            
            rr.clear();
            for (int i = 0; i < N; ++i) {
                if (bit & (1<<i)) rr.PB(inst[i]);
            }
            prr.clear();
            ir = rr[0];
            for (int i = 1; i < rr.size(); ++i) prr.PB(rr[i]);
            
            //COUT(bit); COUT(rr);
            
            DD ta = -1;
            pair<bool, DD> judge;
            vector<DD> ord;
            do {
                r = prr; r.PB(ir);
                Point ip(ir, 0.0);
            
                DD lo = 0.0, up = torad(180);            
                for (int i = 0; i < 50; ++i) {
                    med = (lo + up) / 2;
                
                    Point sp = rot(Point(prr[0], 0.0), med);
                    pol.clear(); pol.PB(ip); pol.PB(sp);
                
                    judge = isexceed(ip, sp);
                    if (judge.FI) up = med;
                    else lo = med;
                }
            
                if (abs(sum - torad(360)) > EPS) continue;
                
                if (ta < judge.SE) {
                    ta = judge.SE; ord = prr;
                }
            } while (next_permutation(ALL(prr)));
            
            //COUT(todeg(med)); cout << pol << ord << ta << endl << endl;
//            if (todeg(med) > 179 || todeg(med) < 1) {
//                COUT(todeg(med));
//                COUT(rr);
//                COUT(pol);
//                COUT(ord);
//                COUT(ta);
//                cout << endl;
//            }
            
            res = max(res, ta);
        }
        
        //cout << res << endl;
        cout << fixed << setprecision(10) << res << endl;
    }
    
    return 0;
}