Problem: Example

Input

4
5
8
58
85


Output

2970.000000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

long double radius[8];

int main(void){
	int n;
	cin >> n;

	set<vector<int>> visited;
	for (int i = 0; i < n; ++i) cin >> radius[i];
	sort(radius,radius+n);

	long double ans=0.0;

	do{
		long double theta[8];
		for(int last=3;last<=n;++last){
			vector<int> cur;
			for(int i=0;i<last;++i) cur.pb(radius[i]);
			if(visited.find(cur)!=visited.end()) continue;
			visited.insert(cur);reverse(cur.begin(),cur.end());visited.insert(cur);

			long double l=0.0,r=pi;
			for(int loop=0;loop<200;++loop){
				long double m=(l+r)/2.0;
				theta[0]=m;
				for(int i=1;i<last;++i){
					long double tmp=1.0*(radius[0]*radius[1])/(radius[(i)%last]*radius[(i+1)%last])*cos(theta[0]);
					if(tmp>1.0+eps) tmp=1.0;
					if(tmp+eps<-1.0) tmp=-1.0;
					theta[i]=acos(tmp);
					if(theta[i]<-eps) theta[i]+=2.0*pi;
				}

				long double sum=0.0;
				for(int i=0;i<last;++i) sum+=theta[i];
				if(sum<2.0*pi)
					l=m;
				else
					r=m;
			}

			long double res=0.0;
			long double sum=0.0;
			for(int i=0;i<last;++i){
				 res+=(radius[(i)%last]*radius[(i+1)%last])*sin(theta[i])/2.0;
				 sum+=theta[i];
			}
			if(abs(sum-2*pi) < eps) ans=max(ans,res);
		}
	}while(next_permutation(radius,radius+n));

	cout.precision(9);
	cout << fixed <<  ans << endl;
	return 0;
}