Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}
double calc(double R1, double R2) {
    double A = R1 + R2;
    double B = abs(R1 - R2);
    return sqrt(A * A - B * B);
}
int main(){
    iostream_init();
    int n;
    cin >> n;
    vector<double> r(n);
    REP(i, n) cin >> r[i];
    vector<double> d(n);
    REP(i, n) {
        d[i] = r[i];
        for(int j = 0; j < i; j++) {
            d[i] = max(d[i], d[j] + calc(r[i], r[j]));
        }
    }
    double ans = 0;
    REP(i, n) ans = max(ans, d[i] + r[i]);
    cout << ans << endl;
    return 0;
}