Language: C++

#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(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 SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int MOD = 1000000007;
const int INF = 2000000000;
const long double PI = acosl(-1);
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}
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; }

int power(int N, int M) {return M ? power(N * N, M / 2) * (M % 2 ? N : 1) : 1;}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int N;
    cin >> N;
    vector<int> A(N + 1);
    REP (i, N + 1) {
        cin >> A[i];
    }

    int ans = 0;
    if (N == 0) {
        if (A[0] == 1) {
            p(1);
            return 0;
        }
        else {
            p(-1);
            return 0;
        }
    }
    if (A[0] >= 1) {
        p(-1);
        return 0;
    }
    VI B(N+1);
    B[0] = 1;
    REP(i,min(28LL,N)) {
        B[i+1] = min((B[i]-A[i]) * 2,8*power(10,8));
    }
    REP(i,N+1) {
        if (i > 27) break;
        if (A[i] > power(2,i)) {
            p(-1);
            return 0;
        }
    }
    ans = A[N];
    int now = A[N];
    for (int i = N-1; i >= 0; i--) {
        now = min(now + A[i], B[i]);
        ans += now;
    }
    pa;
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/nomura2020/nomura2020_c && sh test.sh
cd ~/Desktop/Programming/AtCoder/contest/nomura2020/nomura2020_c && sh etest.sh
cd ~/Desktop/Programming/AtCoder/contest/nomura2020/nomura2020_c && sh submit.sh
*/


Compiler output:
a.cc: In function 'int main()':
a.cc:77:14: error: no matching function for call to 'min(long long int, int64_t&)'
   77 |     REP(i,min(28LL,N)) {
      |           ~~~^~~~~~~~
a.cc:3:47: note: in definition of macro 'REP'
    3 | #define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
      |                                               ^
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:77:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t' {aka 'long int'})
   77 |     REP(i,min(28LL,N)) {
      |           ~~~^~~~~~~~
a.cc:3:47: note: in definition of macro 'REP'
    3 | #define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
      |                                               ^
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:77:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   77 |     REP(i,min(28LL,N)) {
      |           ~~~^~~~~~~~
a.cc:3:47: note: in definition of macro 'REP'
    3 | #define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
      |                                               ^