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)

template <class T, class U>
inline bool chmax(T& t, const U& f) { return t < f ? t = f, true : false; }

inline double sqr(double x) { return x * x; }

double solve(int N, vector<double>& r) {
    vector<double> x = r;
    rep(i, N) rep(j, i) chmax(x[i], x[j] + sqrt(sqr(r[i] + r[j]) - sqr(r[i] - r[j])));
    double L = 0.0;
    rep(i, N) chmax(L, x[i] + r[i]);
    return L;
}

int main() {
    int N; cin >> N;
    vector<double> r(N);
    for (auto& e : r) cin >> e;
    cout << fixed << setprecision(8) << solve(N, r) << endl;
}