Language: C++

#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n; n++;
    vector<ll> a(n), ca(60), cld(60);
    rep(i,n) cin>>a[i];

    ca[0] = 1;
    bool ok = true;
    ll ans = 0;
    rep(i,min(n,50)) {
        if (ca[i] < a[i]) {
            cout << -1 << '\n';
            return 0;
        }
        cld[i] = 2*(ca[i]-a[i]);
        ca[i+1] = cld[i];
    }

    ll cur = 0;
    for (int i = n-1; i >= min(n,50); --i) {
        ans += a[i]+ans;
    }
    for (int i = min(n,50)-1; i >= 0; --i) {
        // cout << "a[i] = " << a[i] << '\n';
        cur = min(cur+a[i], ca[i]);
        ans += cur;
    }

    cout << ans << '\n';

    return 0;
}#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n; n++;
    vector<ll> a(n), ca(60), cld(60);
    rep(i,n) cin>>a[i];

    ca[0] = 1;
    bool ok = true;
    ll ans = 0;
    rep(i,min(n,50)) {
        if (ca[i] < a[i]) {
            cout << -1 << '\n';
            return 0;
        }
        cld[i] = 2*(ca[i]-a[i]);
        ca[i+1] = cld[i];
    }

    ll cur = 0;
    for (int i = n-1; i >= min(n,50); --i) {
        ans += a[i]+ans;
    }
    for (int i = min(n,50)-1; i >= 0; --i) {
        // cout << "a[i] = " << a[i] << '\n';
        cur = min(cur+a[i], ca[i]);
        ans += cur;
    }

    cout << ans << '\n';

    return 0;
}

Compiler output:
a.cc:91:2: error: stray '#' in program
   91 | }#include <bits/stdc++.h>
      |  ^
a.cc:91:3: error: 'include' does not name a type
   91 | }#include <bits/stdc++.h>
      |   ^~~~~~~
a.cc:93:11: error: redefinition of 'const int MOD'
   93 | const int MOD = 1e9+7;
      |           ^~~
a.cc:3:11: note: 'const int MOD' previously defined here
    3 | const int MOD = 1e9+7;
      |           ^~~
a.cc:94:17: error: redefinition of 'const long long int LINF'
   94 | const long long LINF = 1e18;
      |                 ^~~~
a.cc:4:17: note: 'const long long int LINF' previously defined here
    4 | const long long LINF = 1e18;
      |                 ^~~~
a.cc:105:6: error: redefinition of 'template<class T> void print(const std::vector<_Tp>&)'
  105 | void print(const vector<T> &x) {
      |      ^~~~~
a.cc:15:6: note: 'template<class T> void print(const std::vector<_Tp>&)' previously declared here
   15 | void print(const vector<T> &x) {
      |      ^~~~~
a.cc:115:6: error: redefinition of 'template<class T> void print(const std::vector<std::vector<_Tp> >&)'
  115 | void print(const vector<vector<T>> &x) {
      |      ^~~~~
a.cc:25:6: note: 'template<class T> void print(const std::vector<std::vector<_Tp> >&)' previously declared here
   25 | void print(const vector<vector<T>> &x) {
      |      ^~~~~
a.cc:126:6: error: redefinition of 'template<class T> void print(const std::vector<_Tp>&, int)'
  126 | void print(const vector<T> &x, int n) {
      |      ^~~~~
a.cc:36:6: note: 'template<class T> void print(const std::vector<_Tp>&, int)' previously declared here
   36 | void print(const vector<T> &x, int n) {
      |      ^~~~~
a.cc:135:6: error: redefinition of 'template<class T> void print(const std::vector<std::vector<_Tp> >&, int, int)'
  135 | void print(const vector<vector<T>> &x, int n, int m) {
      |      ^~~~~
a.cc:45:6: note: 'template<class T> void print(const std::vector<std::vector<_Tp> >&, int, int)' previously declared here
   45 | void print(const vector<vector<T>> &x, int n, int m) {
      |      ^~~~~
a.cc:144:31: error: redefinition of 'template<class T> bool chmax(T&, T)'
  144 | template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
      |                               ^~~~~
a.cc:54:31: note: 'template<class T> bool chmax(T&, T)' previously declared here
   54 | template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
      |                               ^~~~~
a.cc:145:31: error: redefinition of 'template<class T> bool chmin(T&, T)'
  145 | template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
      |                               ^~~~~
a.cc:55:31: note: 'template<class T> bool chmin(T&, T)' previously declared here
   55 | template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
      |                               ^~~~~
a.cc:147:6: error: redefinition of 'void input_init()'
  147 | void input_init() {
      |      ^~~~~~~~~~
a.cc:57:6: note: 'void input_init()' previously defined here
   57 | void input_init() {
      |      ^~~~~~~~~~
a.cc:151:5: error: redefinition of 'int main(int, const char**)'
  151 | int main(int argc, char const *argv[]) {
      |     ^~~~
a.cc:61:5: note: 'int main(int, const char**)' previously defined here
   61 | int main(int argc, char const *argv[]) {
      |     ^~~~