Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	int n;
	cin >> n;
	vector<ld> v(n), pos(n);
	REP(i, n) cin >> v[i];
	if (n == 1)
	{
		cout << v[0] * 2 << endl;
		return 0;
	}
	pos[0] = v[0];
	int t;
	ld ans = 0;
	FOR(i, 1, n)
	{
		ld npos = v[i];
		REP(j, i)
		{
			ld l = v[i], r = v[j];
			ld h = abs(l - r), d = l + r;
			ld tmp = pos[j] + sqrt(d*d - h*h);
			chmax(npos, tmp);
		}
		pos[i] = npos;
		chmax(ans, pos[i] + v[i]);
	}
	cout << D10 << ans << endl;
	return 0;
}