Language: C++

#define int ll
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n+1);
    rep(i,n+1) cin >> a[i];
    vector<int> a_m(n+1);
    a_m[n] = 0;
    for(int i = n-1; i >= 0; i--) {
        a_m[i] = a_m[i+1]+a[i+1];
    }
    vector<int> v(n+1);
    if(a[0] >= 2 || (a[0]==1 && n != 0)) {
        cout << -1 << endl;
        return 0;
    }
    if(a[0] == 1 && n == 0) {
        cout << 1 << endl;
        return 0;
    }
    int ans = 1;
    v[0] = 1;
    for(int i = 1; i <= n; i++) {
        v[i] = min(2*v[i-1]-a[i], a_m[i]);
        if(a[i] + v[i] < v[i-1]) {
            cout << -1 << endl;
            return 0;
        }
        ans += v[i];
        ans += a[i];
    }
    cout << ans << endl;
}


Compiler output:
In file included from /usr/include/c++/14/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:33,
                 from a.cc:2:
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:310:33: error: expected initializer before 'size_t'
  310 |   typedef __SIZE_TYPE__         size_t;
      |                                 ^~~~~~
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:311:33: error: expected initializer before 'ptrdiff_t'
  311 |   typedef __PTRDIFF_TYPE__      ptrdiff_t;
      |                                 ^~~~~~~~~
a.cc:1:13: error: 'll' has not been declared
    1 | #define int ll
      |             ^~
In file included from /usr/include/c++/14/cassert:44:
/usr/include/assert.h:70:41: error: expected ',' or '...' before '__line'
   70 |                            unsigned int __line, const char *__function)
      |                                         ^~~~~~
/usr/include/assert.h:74:13: error: variable or field '__assert_perror_fail' declared void
   74 | extern void __assert_perror_fail (int __errnum, const char *__file,
      |             ^~~~~~~~~~~~~~~~~~~~
a.cc:1:13: error: 'll' was not declared in this scope
    1 | #define int ll
      |             ^~
/usr/include/assert.h:74:49: error: expected primary-expression before 'const'
   74 | extern void __assert_perror_fail (int __errnum, const char *__file,
      |                                                 ^~~~~
/usr/include/assert.h:75:35: error: expected primary-expression before 'unsigned'
   75 |                                   unsigned int __line, const char *__function)
      |                                   ^~~~~~~~
/usr/include/assert.h:75:56: error: expected primary-expression before 'const'
   75 |                                   unsigned int __line, const char *__function)
      |                                                        ^~~~~
a.cc:1:13: error: 'll' has not been declared
    1 | #define int ll
      |             ^~
In file included from /usr/include/ctype.h:26,
                 from /usr/include/c++/14/cctype:42,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:35:
/usr/include/x86_64-linux-gnu/bits/types.h:32:28: error: expected initializer before '__u_short'
   32 | typedef unsigned short int __u_short;
      |                            ^~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:33:22: error: expected initializer before '__u_int'
   33 | typedef unsigned int __u_int;
      |                      ^~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:34:27: error: expected initializer before '__u_long'
   34 | typedef unsigned long int __u_long;
      |                           ^~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:39:26: error: expected initializer before '__int16_t'
   39 | typedef signed short int __int16_t;
      |                          ^~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:40:28: error: expected initializer before '__uint16_t'
   40 | typedef unsigned short int __uint16_t;
      |                            ^~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:41:20: error: expected initializer before '__int32_t'
   41 | typedef signed int __int32_t;
      |                    ^~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:42:22: error: expected initializer before '__uint32_t'
   42 | typedef unsigned int __uint32_t;
      |                      ^~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:44:25: error: expected initializer before '__int64_t'
   44 | typedef signed long int __int64_t;
      |                         ^~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:45:27: error: expected initializer before '__uint64_t'
   45 | typedef unsigned long int __uint64_t;
      |                           ^~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:54:9: error: '__int16_t' does not name a type; did you mean '__int8_t'?
   54 | typedef __int16_t __int_least16_t;
      |         ^~~~~~~~~
      |         __int8_t
/usr/include/x86_64-linux-gnu/bits/types.h:55:9: error: '__uint16_t' does not name a type; did you mean '__uint8_t'?
   55 | typedef __uint16_t __uint_least16_t;
      |         ^~~~~~~~~~
      |         __uint8_t
/usr/include/x86_64-linux-gnu/bits/types.h:56:9: error: '__int32_t' does not name a type; did you mean '__int8_t'?
   56 | typedef __int32_t __int_least32_t;
      |         ^~~~~~~~~
      |         __int8_t
/usr/include/x86_64-linux-gnu/bits/types.h:57:9: error: '__uint32_t' does not name a type; did you mean '__uint8_t'?
   57 | typedef __uint32_t __uint_least32_t;
      |         ^~~~~~~~~~
      |         __uint8_t
/usr/include/x86_64-linux-gnu/bits/types.h:58:9: error: '__int64_t' does not name a type; did you mean '__int8_t'?
   58 | typedef __int64_t __int_least64_t;
      |         ^~~~~~~~~
      |         __int8_t
/usr/include/x86_64-linux-gnu/bits/types.h:59:9: error: '__uint64_t' does not name a type; did you mean '__uint8_t'?
   59 | typedef __uint64_t __uint_least64_t;
      |         ^~~~~~~~~~
      |         __uint8_t
/usr/include/x86_64-linux-gnu/bits/types.h:63:18: error: expected initializer before '__quad_t'
   63 | typedef long int __quad_t;
      |                  ^~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:64:27: error: expected initializer before '__u_quad_t'
   64 | typedef unsigned long int __u_quad_t;
      |                           ^~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:72:18: error: expected initializer before '__intmax_t'
   72 | typedef long int __intmax_t;
      |                  ^~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:73:27: error: expected initializer before '__uintmax_t'
   73 | typedef unsigned long int __uintmax_t;
      |                           ^~~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:145:25: error: expected initializer before '__dev_t'
  145 | __STD_TYPE __DEV_T_TYPE __dev_t;        /* Type of device numbers.  */
      |                         ^~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:146:25: error: expected initializer before '__uid_t'
  146 | __STD_TYPE __UID_T_TYPE __uid_t;        /* Type of user identifications.  */
      |                         ^~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:147:25: error: expected initializer before '__gid_t'
  147 | __STD_TYPE __GID_T_TYPE __gid_t;        /* Type of group identifications.  */
      |                         ^~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:148:25: error: expected initializer before '__ino_t'
  148 | __STD_TYPE __INO_T_TYPE __ino_t;        /* Type of file serial numbers.  */
      |                         ^~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:149:27: error: expected initializer before '__ino64_t'
  149 | __STD_TYPE __INO64_T_TYPE __ino64_t;    /* Type of file serial numbers (LFS).*/
      |                           ^~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:150:26: error: expected initializer before '__mode_t'
  150 | __STD_TYPE __MODE_T_TYPE __mode_t;      /* Type of file attribute bitmasks.  */
      |                          ^~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:151:27: error: expected initializer before '__nlink_t'
  151 | __STD_TYPE __NLINK_T_TYPE __nlink_t;    /* Type of file link counts.  */
      |                           ^~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:152:25: error: expected initializer before '__off_t'
  152 | __STD_TYPE __OFF_T_TYPE __off_t;        /* Type of file sizes and offsets.  */
      |                         ^~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:153:27: error: expected initializer before '__off64_t'
  153 | __STD_TYPE __OFF64_T_TYPE __off64_t;    /* Type of file sizes and offsets (LFS).  */
      |                           ^~~~~~~~~
a.cc:1:13: error: 'll' does not name a type
    1 | #define int ll
      |             ^~
a.cc:1:13: error: 'll' does not name a type
    1 | #define int ll
      |             ^~
/usr/include/x86_64-linux-gnu/bits/types.h:156:27: error: expected initializer before '__clock_t'
  156 | __STD_TYPE __CLOCK_T_TYPE __clock_t;    /* Type of CPU usage counts.  */
      |                           ^~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:157:26: error: expected initializer before '__rlim_t'
  157 | __STD_TYPE __RLIM_T_TYPE __rlim_t;      /* Type for resource measurement.  */
      |                          ^~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:158:28: error: expected initializer before '__rlim64_t'
  158 | __STD_TYPE __RLIM64_T_TYPE __rlim64_t;  /* Type for resource measurement (LFS).  */
      |                            ^~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:159:24: error: expected initializer before '__id_t'
  159 | __STD_TYPE __ID_T_TYPE __id_t;          /* General type for IDs.  */
      |                        ^~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:160:26: error: expected initializer before '__time_t'
  160 | __STD_TYPE __TIME_T_TYPE __time_t;      /* Seconds since the Epoch.  */
      |                          ^~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:161:30: error: expected initializer before '__useconds_t'
  161 | __STD_TYPE __USECONDS_T_TYPE __useconds_t; /* Count of microseconds.  */
      |                              ^~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:162:31: error: expected initializer before '__suseconds_t'
  162 | __STD_TYPE __SUSECONDS_T_TYPE __suseconds_t; /* Signed count of microseconds.  */
      |                               ^~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:163:33: error: expected initializer before '__suseconds64_t'
  163 | __STD_TYPE __SUSECONDS64_T_TYPE __suseconds64_t;
      |                                 ^~~~~~~~~~~~~~~
a.cc:1:13: error: 'll' does not name a type
    1 | #define int ll
      |             ^~
a.cc:1:13: error: 'll' does not name a type
    1 | #define int ll
      |             ^~
a.cc:1:13: error: 'll' does not name a type
    1 | #define int ll
      |             ^~
/usr/include/x86_64-linux-gnu/bits/types.h:175:29: error: expected initializer before '__blksize_t'
  175 | __STD_TYPE __BLKSIZE_T_TYPE __blksize_t;
      |