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<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n;
double r[500], pos[500];
double f(double a, double b){
	return sqrt(4 * a * b);
}
int main(){
	cin >> n;
	rep(i, n) cin >> r[i];
	pos[0] = r[0];
	for(int i = 1; i < n; i++){
		
		double mx = 0;
		rep(j, i) mx = max(mx, pos[j] + f(r[i], r[j]));
		pos[i] = max(r[i], mx);
	}
	double ans = 0;
	rep(i, n){
		ans = max(ans, pos[i] + r[i]);
	}
	printf("%.20f\n", ans);
	
	return 0;
}