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 FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

typedef long long ll;

int n;
double rs[525];
double xs[525];

typedef complex<double> P;

int main(){
  cin>>n;
  REP(i,n)cin>>rs[i];
  xs[0] = rs[0];
  FOR(i,1,n){
    double low = max(xs[i-1], rs[i]);
    double high = 1e9;
    REP(_,100){
      double x = (low+high)/2.0;
      P rc = P(x, rs[i]);
      bool col = false;
      FORR(j,0,i){
        P lc = P(xs[j], rs[j]);
        if(abs(lc - rc) <= rs[i] + rs[j]){
          col = true;
          break;
        }
      }
      if(col){
        low = x;
      }else{
        high = x;
      }
    }
    xs[i] = high;
  }
  double ans = 0.0;
  REP(i,n)ans = max(ans, xs[i]+rs[i]);
  printf("%.9f\n",ans);
  return 0;
}