Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)
#define for(i, m, n) for(int i = m; i < n; i++)
#define forr(i,m,n) for(int i = m - 1; i >= n; i--)
#define all(v) v.begin(), v.end()
#define itn int
#define yes() cout << "yes" << endl
#define no() cout << "no" << endl
#define yes() cout << "yes" << endl
#define no() cout << "no" << endl
#define println(x) cout << x << endl
#define print(x) cout << x << " "
template<typename t, typename u>
inline bool cmax(t &m, u x) { if (m < x) { m = x; return true; } return false; }
template<typename t, typename u>
inline bool cmin(t &m, u x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int inf = 1e9;
const lint linf = 1e18;
const int mod = 1e9+7;
int main(){
    int n;
    cin >> n;
    lint child = 0;
    lint ans = 0;
    vector<lint> a(n + 1);
    vector<lint> f(n + 1);
    rep(i,n + 1) cin >> a[i];
    f[0] = 1;
    if(f[0] < a[0]){
        println(-1);
        return 0;
    }
    rep(i,n){
        if((f[i] - a[i]) <= linf / 2)
            f[i + 1] = (f[i] - a[i]) * 2;
        else{
            f[i + 1] = linf;
        }
        if(f[i + 1] < a[i + 1]){
            println(-1);
            return 0;
        }
    }
    repr(i,n + 1){
        if(i == n){
            ans += a[i];
            child = a[i];
        }else{
            lint res = min(child + a[i],f[i]);
            ans += res;
            child = res;
        }
    }
    println(ans);
    return 0;
}

Compiler output:
a.cc:32:16: error: macro "for" requires 3 arguments, but only 1 given
   32 |     rep(i,n + 1) cin >> a[i];
      |                ^
a.cc:5:9: note: macro "for" defined here
    5 | #define for(i, m, n) for(int i = m; i < n; i++)
      |         ^~~
a.cc:38:12: error: macro "for" requires 3 arguments, but only 1 given
   38 |     rep(i,n){
      |            ^
a.cc:5:9: note: macro "for" defined here
    5 | #define for(i, m, n) for(int i = m; i < n; i++)
      |         ^~~
a.cc:49:17: error: macro "for" requires 3 arguments, but only 1 given
   49 |     repr(i,n + 1){
      |                 ^
a.cc:5:9: note: macro "for" defined here
    5 | #define for(i, m, n) for(int i = m; i < n; i++)
      |         ^~~
a.cc: In function 'int main()':
a.cc:32:18: error: expected '(' before 'cin'
   32 |     rep(i,n + 1) cin >> a[i];
      |                  ^~~
      |                  (
a.cc:32:27: error: 'i' was not declared in this scope
   32 |     rep(i,n + 1) cin >> a[i];
      |                           ^
a.cc:34:5: error: expected primary-expression before 'if'
   34 |     if(f[0] < a[0]){
      |     ^~
a.cc:33:14: error: expected ')' before 'if'
   33 |     f[0] = 1;
      |              ^
      |              )
   34 |     if(f[0] < a[0]){
      |     ~~        
a.cc:32:18: note: to match this '('
   32 |     rep(i,n + 1) cin >> a[i];
      |                  ^~~
a.cc:38:13: error: expected '(' before '{' token
   38 |     rep(i,n){
      |             ^
      |             (
a.cc:38:13: error: expected primary-expression before '{' token
a.cc:4:20: error: expected primary-expression before 'for'
    4 | #define repr(i, n) for(int i = n - 1; i >= 0; i--)
      |                    ^~~
a.cc:49:5: note: in expansion of macro 'repr'
   49 |     repr(i,n + 1){
      |     ^~~~
a.cc:48:6: error: expected ';' before 'for'
   48 |     }
      |      ^
      |      ;
a.cc:4:20: error: expected primary-expression before 'for'
    4 | #define repr(i, n) for(int i = n - 1; i >= 0; i--)
      |                    ^~~
a.cc:49:5: note: in expansion of macro 'repr'
   49 |     repr(i,n + 1){
      |     ^~~~
a.cc:48:6: error: expected ')' before 'for'
   48 |     }
      |      ^
      |      )
a.cc:38:13: note: to match this '('
   38 |     rep(i,n){
      |             ^
a.cc:49:18: error: expected '(' before '{' token
   49 |     repr(i,n + 1){
      |                  ^
      |                  (
a.cc:49:18: error: expected primary-expression before '{' token
a.cc:60:5: error: expected primary-expression before 'return'
   60 |     return 0;
      |     ^~~~~~
a.cc:59:18: error: expected ')' before 'return'
   59 |     println(ans);
      |                  ^
      |                  )
   60 |     return 0;
      |     ~~~~~~        
a.cc:49:18: note: to match this '('
   49 |     repr(i,n + 1){
      |                  ^