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++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef pair<int,int> P;

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

int main(){
	cin >> n;
	rep(i,n) cin >> r[i];
	rep(i,n){
		dist[i] = r[i];
		rep(j,i){
			dist[i] = max(dist[i],dist[j]+sqrt(pow(r[j]+r[i],2)-pow(r[j]-r[i],2)));
		}
	}
	double ans = 0.0;
	rep(i,n) ans = max(ans,dist[i]+r[i]);
	printf("%.9f\n",ans);
}