Problem: Example

Input

4
5
8
58
85


Output

2970.000000000

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N;
int POW[9];
double table[9];

double calc(vector<double> G){

	double need_sum = 2*M_PI;
	double table[G.size()],base;

	double left = 0,right = M_PI,mid = (left+right)/2;
	double tmp_value,tmp_sum;

	for(int loop = 0; loop < 50; loop++){

		base = G[0]*G[1]*cos(mid);
		table[0] = mid;
		tmp_sum = mid;

		for(int i = 1; i < G.size(); i++){
			tmp_value = base/(G[i]*G[(i+1)%G.size()]);
			table[i] = acos(tmp_value);
			tmp_sum += table[i];
		}

		if(fabs(tmp_sum-need_sum) < EPS){
			double ret = 0;
			for(int i = 0; i < G.size(); i++){
				ret += G[i]*G[(i+1)%G.size()]*sin(table[i]);
			}
			ret /= 2;

			return ret;

			break;
		}

		if(tmp_sum > need_sum){
			right = mid-EPS;
		}else{
			left = mid+EPS;
		}
		mid = (left+right)/2;
	}

	return -1;
}

int main(){

	POW[0] = 1;

	for(int i = 1; i < 9; i++){
		POW[i] = POW[i-1]*2;
	}

	scanf("%d",&N);

	for(int i = 0; i < N; i++){
		scanf("%lf",&table[i]);
	}

	vector<double> TMP;
	double ans = 0;
	int count;

	for(int state = 1; state < POW[N];state++){

		count = 0;
		TMP.clear();

		for(int loop = 0; loop < N; loop++){
			if(state&(1 << loop)){
				count++;
				TMP.push_back(table[loop]);
			}
		}
		if(count < 2)continue;

		sort(TMP.begin(),TMP.end());

		do{
			ans = max(ans,calc(TMP));

		}while(next_permutation(TMP.begin(),TMP.end()));
	}

	printf("%.10lf\n",ans);

	return 0;
}