Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
// {{{ Boilerplate Code <--------------------------------------------------
// vim:filetype=cpp:foldmethod=marker:foldmarker={{{,}}}

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define ALL(A)     (A).begin(), (A).end()

using namespace std;

// }}}

int main(){
	int n;

	vector <double> d;

	cin>>n;

	FOR(i,0,n){
		int tmp;
		cin>>tmp;
		d.push_back(tmp);
	}

	vector <double> pos;

	double ret = 0.0;

	FOR(i,0,n){
		double curpos = 0.0;

		curpos=max(curpos,d[i]);

		FOR(j,0,i){
			double e1=d[i]-d[j];
			double e2=d[i]+d[j];
			double e3=sqrt(e2*e2-e1*e1);

			curpos=max(curpos,pos[j]+e3);
		}
		pos.push_back(curpos);

		ret=max(ret,curpos+d[i]);
	}

	cout<<setprecision(15)<<ret<<endl;

}