Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n;
  cin >>n;
  vector<ll> a(n+1);
  ll nl=0;//葉の数
  rep(i,n+1) {
    cin >>a[i];
    nl+=a[i];
  }
  ll nb=nl-1;//合計分岐数
  
  ll ans=0;
  vector<ll> c(n+1);//深さiの頂点の数．
  c[n]=a[n]; 
  c[0]=1;
  ll cb=0;//これまでの合計分岐数．
  ans+=c[0];
  
  for(int i=1;i<n+1;i++){
    if(c[i-1]<a[i-1]){//数が足りない時．
      cout<<-1<<endl;
     return 0; 
    }
      
    if(cb==nb){//もう分岐できない場合．
      c[i]=c[i-1]-a[i-1];
    }else if(cb+c[i-1]-a[i-1]<=nb){ //まだ分岐できる場合．
      c[i]=2*(c[i-1]-a[i-1]);
      cb+=(c[i-1]-a[i-1]);
    }else if(cb<nb){ //分岐数に限りがある場合
      c[i]=(nb-cb)+c[i-1];
      cb=nb;
    }
    
    ans+=c[i];
  }

  
  cout<<ans<<endl;
  
}


Compiler output:
a.cc: In function 'int main()':
a.cc:6:3: error: 'll' was not declared in this scope
    6 |   ll n;
      |   ^~
a.cc:7:9: error: 'n' was not declared in this scope; did you mean 'yn'?
    7 |   cin >>n;
      |         ^
      |         yn
a.cc:8:12: error: template argument 2 is invalid
    8 |   vector<ll> a(n+1);
      |            ^
a.cc:9:5: error: expected ';' before 'nl'
    9 |   ll nl=0;//葉の数
      |     ^~~
      |     ;
a.cc:11:12: error: invalid types 'int[int]' for array subscript
   11 |     cin >>a[i];
      |            ^
a.cc:12:5: error: 'nl' was not declared in this scope; did you mean 'ynl'?
   12 |     nl+=a[i];
      |     ^~
      |     ynl
a.cc:12:10: error: invalid types 'int[int]' for array subscript
   12 |     nl+=a[i];
      |          ^
a.cc:14:5: error: expected ';' before 'nb'
   14 |   ll nb=nl-1;//合計分岐数
      |     ^~~
      |     ;
a.cc:16:5: error: expected ';' before 'ans'
   16 |   ll ans=0;
      |     ^~~~
      |     ;
a.cc:17:12: error: template argument 2 is invalid
   17 |   vector<ll> c(n+1);//深さiの頂点の数．
      |            ^
a.cc:19:4: error: invalid types 'int[int]' for array subscript
   19 |   c[0]=1;
      |    ^
a.cc:20:5: error: expected ';' before 'cb'
   20 |   ll cb=0;//これまでの合計分岐数．
      |     ^~~
      |     ;
a.cc:21:3: error: 'ans' was not declared in this scope; did you mean 'abs'?
   21 |   ans+=c[0];
      |   ^~~
      |   abs
a.cc:21:9: error: invalid types 'int[int]' for array subscript
   21 |   ans+=c[0];
      |         ^
a.cc:24:9: error: invalid types 'int[int]' for array subscript
   24 |     if(c[i-1]<a[i-1]){//数が足りない時．
      |         ^
a.cc:24:16: error: invalid types 'int[int]' for array subscript
   24 |     if(c[i-1]<a[i-1]){//数が足りない時．
      |                ^
a.cc:29:8: error: 'cb' was not declared in this scope; did you mean 'c'?
   29 |     if(cb==nb){//もう分岐できない場合．
      |        ^~
      |        c
a.cc:29:12: error: 'nb' was not declared in this scope
   29 |     if(cb==nb){//もう分岐できない場合．
      |            ^~
a.cc:30:8: error: invalid types 'int[int]' for array subscript
   30 |       c[i]=c[i-1]-a[i-1];
      |        ^
a.cc:30:13: error: invalid types 'int[int]' for array subscript
   30 |       c[i]=c[i-1]-a[i-1];
      |             ^
a.cc:30:20: error: invalid types 'int[int]' for array subscript
   30 |       c[i]=c[i-1]-a[i-1];
      |                    ^
a.cc:31:18: error: invalid types 'int[int]' for array subscript
   31 |     }else if(cb+c[i-1]-a[i-1]<=nb){ //まだ分岐できる場合．
      |                  ^
a.cc:31:25: error: invalid types 'int[int]' for array subscript
   31 |     }else if(cb+c[i-1]-a[i-1]<=nb){ //まだ分岐できる場合．
      |                         ^
a.cc:32:8: error: invalid types 'int[int]' for array subscript
   32 |       c[i]=2*(c[i-1]-a[i-1]);
      |        ^
a.cc:32:16: error: invalid types 'int[int]' for array subscript
   32 |       c[i]=2*(c[i-1]-a[i-1]);
      |                ^
a.cc:32:23: error: invalid types 'int[int]' for array subscript
   32 |       c[i]=2*(c[i-1]-a[i-1]);
      |                       ^
a.cc:33:13: error: invalid types 'int[int]' for array subscript
   33 |       cb+=(c[i-1]-a[i-1]);
      |             ^
a.cc:33:20: error: invalid types 'int[int]' for array subscript
   33 |       cb+=(c[i-1]-a[i-1]);
      |                    ^
a.cc:35:8: error: invalid types 'int[int]' for array subscript
   35 |       c[i]=(nb-cb)+c[i-1];
      |        ^
a.cc:35:21: error: invalid types 'int[int]' for array subscript
   35 |       c[i]=(nb-cb)+c[i-1];
      |                     ^
a.cc:39:11: error: invalid types 'int[int]' for array subscript
   39 |     ans+=c[i];
      |           ^