Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <stdio.h>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ld,ld>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORa(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define FORs(i,st) for(auto i : st)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n;
    cin>>n;
    vector<P> cylinders;
    FOR(i,0,n){
      ld r;
      cin>>r;
      ld distance = r;
      FOR(j,0,cylinders.size()){
        ld x = 2*sqrt(cylinders[j].second * r) + cylinders[j].first;
        distance = max(distance, x);
      }
      cylinders.push_back(P(distance,r));
    }
    ld ans=0;
    FOR(i,0,n){
      ans = max(ans,cylinders[i].first + cylinders[i].second);
    }
    cout(10)<<ans<<endl;
}