Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
#define indexOf(v,x) (find(all(v),x)-v.begin())


int n;
double r[500];
double x[500];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	rep(i, n)cin >> r[i];
	rep(i,n) {
		double mx = r[i];
		rep(j,i) {
			double a = x[j] + sqrt((r[j]+r[i])*(r[j]+r[i])-(r[j]-r[i])*(r[j]-r[i]));
			mx = max(mx,a);
		}
		x[i] = mx;
	}
	double ans = 0;
	rep(i,n) {
		ans = max(ans,x[i]+r[i]);
	}
	printf("%.6f\n",ans);
	return 0;
}