Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)

double a[510];
int n;

double solve(){
    vector<double> x;
    x.push_back(a[0]);
    for(int i = 1; i < n; i++){
        double left = a[i];
        rep(j,i){
            double p = a[i]+a[j];
            double q = a[i]-a[j];
            double dx = sqrt(p*p - q*q);
            left = max(left, dx + x[j]);
        }
        x.push_back(left);
    }
    double res = 0;
    rep(i,n) res = max(res, x[i]+a[i]);
    return res;
}

int main(){
    while(cin >> n){
        rep(i,n) cin >> a[i];
        printf("%.10lf\n", solve());
    }
}