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++)
#define all(n) begin(n), end(n)
#define dump(x) cerr << #x << " = " << x << endl
#define pb push_back

double a[510];
int n;

double solve(){
    vector<double> x;
    x.pb(a[0]);
    for(int i = 1; i < n; i++){
        double leftmost = a[i];
        rep(j,i){
            double p = a[i]+a[j];
            double q = a[i]-a[j];
            double dx = sqrt(p*p - q*q);
            // dump(dx);
            leftmost = max(leftmost, dx + x[j]);
        }
        x.push_back(leftmost);
    }
    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());
    }
}