Language: C++

#include <bits/stdc++.h>
#pragma GCC optimize(3,"Ofast")
using namespace std;

#define  ll __int128
//typedef unsigned long long ll;
typedef pair<int, int> pii;

#define f(i, l, r) for (int i = l; i <= r; i++)
#define rf(i, r, l) for (int i = r; i >= l; i--)
#define all(x) (x).begin(), (x).end()
//#define sf(a) scanf("%d", &a)
#define llsf(a) scanf("%lld", &a)
#define l l
#define r r
#define lch (o << 1)
#define rch (o << 1 | 1)
//#define mid ((l + r) >> 1)
#define mem(x, y) memset(x, y, sizeof(x))
#define mod1(x) ((x>=mod)&&(x-=mod))
#define mod2(x) ((x<0)&&(x+=mod))

const int inf = 2e9 + 7;
//const ll INF = INT64_MAX;
double eps = 1e-6;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
const double pi = acos(-1.0);
#include <bits/stdc++.h>
using namespace std;
inline __int128 sf()
{
	__int128 x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch>'9')
	{
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}

inline void write(__int128 x)
{
	if (x < 0)
	{
		putchar('-');
		x = -x;
	}
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
}

int main()
{
	__int128 a = read();
	__int128 b = read();
	write(a + b);
	return 0;
}
ll a[N];
ll mx[N];
ll num[N];

int main() {
#ifdef local
	int start = clock();
	freopen("in.txt", "r", stdin);
#endif
	bool flag = 1;
	ll n=sf();
	f(i, 0, n) {
		a[i]=sf();
	}
	ll last, now;
	if (a[0] == 0)last = 1; else last = 0;
	f(i, 1, n) {
		now = 2 * last;
		if (i < n) {
			mx[i] = now - a[i];
			last = now - a[i];
		}
		else {
			mx[i] = now;
		}
	}

	if (mx[n] < a[n])flag = 0;
	ll res = a[n];
	ll down = a[n];
	mx[0] = 1;
	rf(i, n - 1, 0) {
		ll miup = (down + 1) / 2;
		if (miup > mx[i])flag = 0;
		now = min(mx[i], down);
		now += a[i];
		res += now;
		num[i] = now;
		down = now;
	}
	f(i, 0, min(n, 30)) {
		if (num[i] > pow(2, i))flag = 0;
	}
	if (flag) {
		write(res);
	}
	else cout << -1;
#ifdef local
	int end = clock();
	cout << '\n' << end - start << "ms";
#endif* /
}


Compiler output:
a.cc:118:7: warning: extra tokens at end of #endif directive [-Wendif-labels]
  118 | #endif* /
      |       ^
a.cc: In function 'int main()':
a.cc:63:26: error: too few arguments to function 'ssize_t read(int, void*, size_t)'
   63 |         __int128 a = read();
      |                      ~~~~^~
In file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,
                 from /usr/include/signal.h:328,
                 from /usr/include/c++/14/csignal:42,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:116,
                 from a.cc:1:
/usr/include/unistd.h:371:16: note: declared here
  371 | extern ssize_t read (int __fd, void *__buf, size_t __nbytes) __wur
      |                ^~~~
a.cc:64:26: error: too few arguments to function 'ssize_t read(int, void*, size_t)'
   64 |         __int128 b = read();
      |                      ~~~~^~
/usr/include/unistd.h:371:16: note: declared here
  371 | extern ssize_t read (int __fd, void *__buf, size_t __nbytes) __wur
      |                ^~~~
a.cc: At global scope:
a.cc:72:5: error: redefinition of 'int main()'
   72 | int main() {
      |     ^~~~
a.cc:61:5: note: 'int main()' previously defined here
   61 | int main()
      |     ^~~~
a.cc: In function 'int main()':
a.cc:108:20: error: no matching function for call to 'min(__int128&, int)'
  108 |         f(i, 0, min(n, 30)) {
      |                 ~~~^~~~~~~
a.cc:9:41: note: in definition of macro 'f'
    9 | #define f(i, l, r) for (int i = l; i <= r; i++)
      |                                         ^
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/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:108:20: note:   deduced conflicting types for parameter 'const _Tp' ('__int128' and 'int')
  108 |         f(i, 0, min(n, 30)) {
      |                 ~~~^~~~~~~
a.cc:9:41: note: in definition of macro 'f'
    9 | #define f(i, l, r) for (int i = l; i <= r; 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:108:20: note:   mismatched types 'std::initializer_list<_Tp>' and '__int128'
  108 |         f(i, 0, min(n, 30)) {
      |                 ~~~^~~~~~~
a.cc:9:41: note: in definition of macro 'f'
    9 | #define f(i, l, r) for (int i = l; i <= r; i++)
      |                                         ^