Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>

using namespace std;

int n;
double ta;
long double r[505], x[505], ans;

long double sq(long double a) {
	return a * a;
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf", &ta);
		x[i] = r[i] = ta;
		for (int j = 0; j < i; j++)
			x[i] = max(x[i], x[j] + sqrt(sq(r[i] + r[j]) - sq(r[i] - r[j])));
		ans = max(ans, x[i] + r[i]);
	}
	printf("%.10lf\n", (double)ans);
	return 0;
}