Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()

using namespace std;
typedef long long int ll;

double dist(double a, double b){
	double h = abs(a-b);
	double r = a+b;
	return sqrt( r*r - h*h );
}
int main(){
	int N;
	double r[1005], x[1005];
	cin >> N;
	rep(i,N) cin >> r[i];
	rep(i,N){
		x[i] = r[i];
		rep(j,i){
			double d = dist(r[i], r[j]);
			x[i] = max(x[i], x[j] + d);
		}
	}
	double ans = 0;
	rep(i,N) ans = max(ans, x[i] + r[i]);
	printf("%.8f\n", ans);
}