Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main(){
	int n;
	cin >> n;
	vector<double> r(n), x(n);
	REP(i,n){
		cin >> r[i];
		x[i] = r[i];
	}
	REP(i,n){
		REP(j,i){
			x[i] = fmax(x[i], x[j] + sqrt(pow(r[i]+r[j],2)-pow(r[i]-r[j],2)));
		}
	}
	double ans = 0.0;
	REP(i,n){
		ans = fmax(ans, x[i]+r[i]);
	}
	printf("%.10f\n", ans);
    return 0;
}