Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(1,n+1):
    ans += (n//i)*(n//i + 1)/2*i
print(int(ans))

Fixed submission:
def cmb(n, r, mod):#コンビネーションの高速計算　
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 5*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, M = map(int, input().split())
ans = 0
for i in range(N+1):
    ans += cmb(N,i,mod)*((-1)**i)*g1[M]*g2[M-i]*((g1[M-i]*g2[M-N])**2)
    ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
#print(p)
s= sum(p[:k])
print(s)

Fixed submission:
α = input()
if α in['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']:
    print('A')
else:
    print('a')

Buggy python submission (verdict: Runtime Error):
α = (input())
if α ='A'or'B'or'C'or'D'or'E'or'F'or'G'or'H'or'I'or'J'or'K'or'L'or'M'or'N'or'O'or'P'or'Q'or'R'or'S'or'T'or'U'or'V'or'W'or'X'or'Y'or'Z':
    print('A')
else:
    print('a')


Fixed submission:
α = input()
if α in['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']:
    print('A')
else:
    print('a')

Buggy python submission (verdict: Runtime Error):
α = (input())
if α = A or B or C or D or E or F or G or H or I or J or K or L or M or N or O or P or Q or R or S or T or U or V or W or X or Y or Z:
    print('A')
else:
    print('a')

Fixed submission:
α = input()
if α in['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']:
    print('A')
else:
    print('a')

Buggy python submission (verdict: Runtime Error):
α = (input())
if α = A or B or C or D or E or F or G or H or I or J or K or L or M or N or O or P or Q or R or S or T or U or V or W or X or Y or Z:
    print(A)
else:
    print(a)


Fixed submission:
α = input()
if α in['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']:
    print('A')
else:
    print('a')
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
p = list(map(int, input().split())
p.sort()
s= sum(p[:k])
print(s)

Fixed submission:
n,k = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
#print(p)
s= sum(p[:k])
print(s)

Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
i=0
p = list(map(int, input().split())
p.sort()
s= sum(p[:k])
print(s)

Fixed submission:
n,k = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
#print(p)
s= sum(p[:k])
print(s)

Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
i=0
p = []
while i < n:
    p.append(int(input()))
    i += 1
#print(p)
#s=0
#l=0
#while l < k:
#    s += min(p)
#    p = p.remove(min(p))
#    l += 1
#print(s)　こっちはうまくいかない
p.sort()
s= sum(p[:k])
print(s)

Fixed submission:
n,k = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
#print(p)
s= sum(p[:k])
print(s)

Buggy python submission (verdict: Runtime Error):
n = int(input())
k = int(input())
i=0
p = []
while i < n:
    p.append(int(input()))
    i += 1

p.sort()
s= sum(p[:k])
print(s)

Fixed submission:
n,k = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
#print(p)
s= sum(p[:k])
print(s)

Buggy python submission (verdict: Runtime Error):
n = int(input())
k = int(input())
i=0
p = []
while i < n:
    p.append(int(input()))
    i += 1
#print(p)
#s=0
#l=0
#while l < k:
#    s += min(p)
#    p = p.remove(min(p))
#    l += 1
#print(s)
p.sort()
s= sum(p[:k])
print(s)

Fixed submission:
n,k = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
#print(p)
s= sum(p[:k])
print(s)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
L = [0]*100000
s = sum(A)
for a in A:
    L[a] += 1 #数字のカウント
Q = int(input())
for i in range(Q):
    B,C = map(int,input().split())
    s += L[B]*(C-B) #合計値の変化
    L[C] += L[B] 
    L[B] = 0 #Bの値の数だけCに移す
    print(s)


Fixed submission:
N = int(input())
A = list(map(int,input().split()))
L = [0]*100001
s = sum(A)
for a in A:
    L[a] += 1 #数字のカウント
Q = int(input())
for i in range(Q):
    B,C = map(int,input().split())
    s += L[B]*(C-B) #合計値の変化
    L[C] += L[B] 
    L[B] = 0 #Bの値の数だけCに移す
    print(s)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
ans = 0
for a in A:
    x = 0
    for b in A:
        if a%b == 0:
            x += 1
            if x == 2:
                break
    if x == 1:
        ans += 1
print(ans)

Fixed submission:
n = int(input())
a = sorted(map(int, input().split()))
b = [0] * (10 ** 6 + 1)
c = [False] * (10 ** 6 + 1)
for i in a:
    b[i] += 1
ans = 0
for i in range(1, 10 ** 6 + 1):
    if not b[i]:
        continue
    if b[i] == 1 and not c[i]:
        ans += 1
    for j in range(1, 10 ** 6 + 1):
        if i * j > 10 ** 6:
            break
        c[i * j] = True
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
ans = 0
for a in A:
    x = 0
    for b in A:
        if a%b == 0:
            x += 1
    if x == 1:
        ans += 1
print(ans)
            


Fixed submission:
n = int(input())
a = sorted(map(int, input().split()))
b = [0] * (10 ** 6 + 1)
c = [False] * (10 ** 6 + 1)
for i in a:
    b[i] += 1
ans = 0
for i in range(1, 10 ** 6 + 1):
    if not b[i]:
        continue
    if b[i] == 1 and not c[i]:
        ans += 1
    for j in range(1, 10 ** 6 + 1):
        if i * j > 10 ** 6:
            break
        c[i * j] = True
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B = input().split()
A = int(A)
B = int(100*B)
print(A*B//100)

Fixed submission:
A,B = input().split()
A = int(A)
B = int(''.join(B.split('.')))
print(A*B//100)
Buggy python submission (verdict: Runtime Error):
import heapq

def binary_search(data, value):
    left = 0            # 探索する範囲の左端を設定
    right = len(data) - 1            # 探索する範囲の右端を設定
    while left <= right:
        mid = (left + right) // 2            # 探索する範囲の中央を計算
        if data[mid] == value:
            # 中央の値と一致した場合は位置を返す
            return mid
        elif data[mid] < value:
            # 中央の値より大きい場合は探索範囲の左を変える
            left = mid + 1
        else:
            # 中央の値より小さい場合は探索範囲の右を変える
            right = mid - 1
    return -1            # 見つからなかった場合

n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
way = [0]
hq = [0]
heapq.heapify(hq)
posi = 0
cycle = 0
while True:
    if not(a[posi] in way):
        rest = way.index(a[posi])
        cycle -= (rest - 1)
        break
    way.append(a[posi])
    heapq.heappush(hq, a[posi])
    posi = a[posi]
    cycle += 1
# print(way)
# print(cycle)
if k < len(way):
    print(way[k] + 1)
else:
    print(way[(k-rest) % cycle + rest] + 1)

Fixed submission:
s = input()
t = input()
if t[:-1] == s:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

# ni - nj = ai + aj (i>j)
# ai - ni = - aj - nj

a1 = [a[i] - (i+1) for i in range(n)]
a2 = [- a[i] - (i+1) for i in range(n)]
ans = 0
for i in range(n):
    ans += a2.count(a1[i])
print(ans)

Fixed submission:
import bisect

n = int(input())
a = list(map(int,input().split()))

# ni - nj = ai + aj (i>j)
# ai - ni = - aj - nj

a1 = sorted([a[i] - (i+1) for i in range(n)])
a2 = sorted([- a[i] - (i+1) for i in range(n)])
ans = 0
for i in range(n):
    left = bisect.bisect_left(a2, a1[i])
    right = bisect.bisect_right(a2, a1[i])
    ans += (right - left)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

s = input()

mod = 2019
n = len(s)
t = [0]*(n+1)
for i in range(1,n+1):
    t[i] = (t[i-1] + int(s[n-i]) * (10**(i-1) % mod)) % mod
# t[i-1] == t[j] mod2019　のとき、i番~j番目が2019の倍数
c = collections.Counter(t)
num = c.values()
ans = 0
for i in num:
    ans += i*(i-1) // 2

print(ans)

Fixed submission:
import collections

s = input()

mod = 2019
n = len(s)
t = [0]*(n+1)
for i in range(1,n+1):
    t[i] = (t[i-1] + int(s[n-i]) * pow(10, i-1, mod)) % mod
c = collections.Counter(t)
num = c.values()
ans = 0
for i in num:
    ans += i*(i-1) // 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    print(a.count(i+1))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

ans = [0]*n
for i in a:
    ans[i-1] += 1

print(*ans, sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

r = [i+1 for i, x in enumerate(s) if x == 'R']
g = [i+1 for i, x in enumerate(s) if x == 'G']
b = [i+1 for i, x in enumerate(s) if x == 'B']

c = 0
for i in range(1,(n+1)//2):
    for j in range(1,n-2*i+1):
        if j in r and j+i in g and j+2*i in b:
            c += 1
        if j in r and j+i in b and j+2*i in g:
            c += 1
        if j in g and j+i in b and j+2*i in r:
            c += 1
        if j in g and j+i in r and j+2*i in b:
            c += 1
        if j in b and j+i in r and j+2*i in g:
            c += 1
        if j in b and j+i in g and j+2*i in r:
            c += 1

ans = (len(r)*len(g)*len(b) - c)
print(ans)

Fixed submission:
def binary_search(data, value):
    left = 0            # 探索する範囲の左端を設定
    right = len(data) - 1            # 探索する範囲の右端を設定
    while left <= right:
        mid = (left + right) // 2            # 探索する範囲の中央を計算
        if data[mid] == value:
            # 中央の値と一致した場合は位置を返す
            return mid
        elif data[mid] < value:
            # 中央の値より大きい場合は探索範囲の左を変える
            left = mid + 1
        else:
            # 中央の値より小さい場合は探索範囲の右を変える
            right = mid - 1
    return -1            # 見つからなかった場合

n = int(input())
s = input()

r = [i+1 for i, x in enumerate(s) if x == 'R']
g = [i+1 for i, x in enumerate(s) if x == 'G']
b = [i+1 for i, x in enumerate(s) if x == 'B']

c = 0
for i in r:
    for j in g:
        if binary_search(b, 2*i - j) != -1:
            c += 1
        if binary_search(b, 2*j - i) != -1:
            c += 1
        if binary_search(b, (i+j)/2) != -1:
            c += 1

ans = (len(r)*len(g)*len(b) - c)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

import collections
count = collections.Counter(a)

import math
def p(n, r):
    return math.factorial(n) // math.factorial(n - r)
def c(n, r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# print(count)
s = 0
for i in count.keys():
    s += c(count[i], 2)
# print(s)

for i in range(n):
    ans = s - c(count[a[i]], 2) + c(count[a[i]] - 1, 2)
    print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))

import collections
count = collections.Counter(a)

import math
def p(n, r):
    return math.factorial(n) // math.factorial(n - r)
def c(n, r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# print(count)
s = 0
cmb = {}
for i in count.keys():
    cmb[i] = (c(count[i], 2),c(count[i] - 1, 2))
    s += cmb[i][0]
# print(s)
# print(cmb)

for i in range(n):
    ans = s - cmb[a[i]][0] + cmb[a[i]][1]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

count = 0
for i in range(q):
    query = input()
    if query == "1":
        count += 1
    else:
        t,f,c = query.split()
        if f == "1":
            if count % 2 == 0:
                s = c + s
            else:
                s = s + c
        else:
            if count % 2 == 0:
                s = s + c
            else:
                s = c + s
if count % 2 == 0:
    print(s)
else:
    print(s[::-1])

Fixed submission:
s = input()
q = int(input())

from collections import deque
s = deque(s)
count = 0
for i in range(q):
    query = input()
    if query == "1":
        count += 1
    else:
        t,f,c = query.split()
        if f == "1":
            if count % 2 == 0:
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if count % 2 == 0:
                s.append(c)
            else:
                s.appendleft(c)
s = "".join(s)
if count % 2 == 0:
    print(s)
else:
    print(s[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for i in range(q):
    query = input()
    if query == "1":
        s = s[::-1]
    else:
        t,f,c = query.split()
        if f == "1":
            s = c + s
        else:
            s = s + c
print(s)

Fixed submission:
s = input()
q = int(input())

from collections import deque
s = deque(s)
count = 0
for i in range(q):
    query = input()
    if query == "1":
        count += 1
    else:
        t,f,c = query.split()
        if f == "1":
            if count % 2 == 0:
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if count % 2 == 0:
                s.append(c)
            else:
                s.appendleft(c)
s = "".join(s)
if count % 2 == 0:
    print(s)
else:
    print(s[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]

import collections
c = collections.Counter(s)
ans = []
word,count = c.most_common()[0]
ans.append(word)
for i in range(1,len(c)):
    wordi,counti = c.most_common()[i]
    if counti == count:
        ans.append(wordi)
    else:
        break
ans.sort()
print(*ans, sep = "\n")

Fixed submission:
n = int(input())
s = [input() for i in range(n)]

import collections
c = collections.Counter(s)
ans = []
most = c.most_common()
word,count = most[0]
ans.append(word)
for i in range(1,len(c)):
    wordi,counti = most[i]
    if counti == count:
        ans.append(wordi)
    else:
        break
ans.sort()
print(*ans, sep = "\n")
Buggy python submission (verdict: Runtime Error):

a1 = int(input())
a2 = int(input())
a3 = int(input())


result = a1 + a2 + a3
if result >= 22:
    print("bust")
else:
    print("win")

Fixed submission:

a = input().split()
# print(a)

result = int(a[0]) + int(a[1]) + int(a[2])
if result >= 22:
    print("bust")
else:
    print("win")

Buggy python submission (verdict: Runtime Error):

a1 = int(input())
a2 = int(input())
a3 = int(input())


result = a1 + a2 + a3
if result >= 22:
    print("bust")
else:
    print("win")

Fixed submission:

a = input().split()
# print(a)

result = int(a[0]) + int(a[1]) + int(a[2])
if result >= 22:
    print("bust")
else:
    print("win")
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    h,w,K=map(int,input().split())
    g=[[_ for _ in input()] for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if g[i][j]=='.':
                g[i][j]=0
            else:
                g[i][j]=1
    n=h+w
    cnt=0
    for i in range(2 ** n):
        gg=deepcopy(g)
        for j in range(n):
            if ((i >> j) & 1):
                if j-h<0:
                    for k in range(w):
                        gg[j][k]=2
                else:
                    for l in range(h):
                        gg[l][j-h]=2
        
        ans=0
        for i in range(h):
            for j in range(w):
                if gg[i][j]==1:
                    ans+=1

        if ans==K:
            cnt+=1
    print(cnt)


    
resolve()

Fixed submission:
from copy import copy, deepcopy # pythonのみ．copyは1次元，deepcopyは多次元．
# from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    h,w,K=map(int,input().split())
    g=[[_ for _ in input()] for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if g[i][j]=='.':
                g[i][j]=0
            else:
                g[i][j]=1
    n=h+w
    cnt=0
    for i in range(2 ** n):
        gg=deepcopy(g)
        for j in range(n):
            if ((i >> j) & 1):
                if j-h<0:
                    for k in range(w):
                        gg[j][k]=2
                else:
                    for l in range(h):
                        gg[l][j-h]=2
        
        ans=0
        for i in range(h):
            for j in range(w):
                if gg[i][j]==1:
                    ans+=1

        if ans==K:
            cnt+=1
    print(cnt)


    
resolve()
Buggy python submission (verdict: Runtime Error):
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4"""
        output = """23"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """100"""
        output = """26879"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10000000"""
        output = """838627288460105"""
        self.assertIO(input, output)


if __name__ == "__main__":
    unittest.main()


Fixed submission:
#!/usr/bin/python3
# import bisect
# from collections import Counter, deque, OrderedDict, defaultdict
# from copy import copy, deepcopy # pythonのみ．copyは1次元，deepcopyは多次元．
# from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    ll=[0]*(n+1)
    for i in range(1,n+1):
        for j in range(i,n+1,i):
            ll[j]+=1
    

    ans=0
    for i in range(1,n+1):
        ans+=i*ll[i]

    print(ans)
        

    
resolve()
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    
    while n>0:
        n-=1
        a,b=divmod(n,26)
        n//=26
        ans+=chr(ord('a')+b)
    for i in ans[::-1]:
        print(i,end='')
    print()
        

    
resolve()

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    ans=''
    
    while n>0:
        n-=1
        a,b=divmod(n,26)
        n//=26
        ans+=chr(ord('a')+b)
    for i in ans[::-1]:
        print(i,end='')
    print()
        

    
resolve()
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        x, n = map(int, input().split())
        if n == 0:
            return x
        else:
            p = list(map(int, input().split()))

            l = [i for i in reversed(range(1, x))]
            r = [i for i in range(x+1, 101)]
            cur = 0
            if x not in p:
                return x
            while True:
                if cur<x:
                    if l[cur] not in p:
                        return l[cur]
                if cur<len(r):
                    if r[cur] not in p:
                        return r[cur]
                cur+=1
    print(main())


resolve()

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        x, n = map(int, input().split())
        if n == 0:
            return x
        else:
            p = list(map(int, input().split()))


            cur = 0
            if x not in p:
                return x
            
            while True:
                if x-cur not in p:
                    return x-cur
                if x+cur not in p:
                    return x+cur

                cur+=1
    print(main())


resolve()

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        x, n = map(int, input().split())
        if n == 0:
            return x
        else:
            p = list(map(int, input().split()))

            l = [i for i in reversed(range(1, x))]
            r = [i for i in range(x+1, 101)]
            cur = 0
            if x not in p:
                return x
            while True:
                if l[cur] not in p:
                    return l[cur]
                if r[cur] not in p:
                    return r[cur]
                cur+=1
    print(main())


resolve()

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        x, n = map(int, input().split())
        if n == 0:
            return x
        else:
            p = list(map(int, input().split()))


            cur = 0
            if x not in p:
                return x
            
            while True:
                if x-cur not in p:
                    return x-cur
                if x+cur not in p:
                    return x+cur

                cur+=1
    print(main())


resolve()
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    l = [0]*(n+1)
    l[n] = (A[n], A[n])
    for i in reversed(range(1, n+1)):
        l[i-1] = (max(math.ceil(l[i][0]/2)+A[i-1], 1), l[i][1]+A[i-1])

    if 1 not in range(l[0][0], l[0][1]+1):
        print(-1)
    else:
        ans = [0]*(n+1)
        ans[0] = 1
        cnt = 1
        for i in range(n):
            ans[i+1] = min((ans[i]-A[i])*2, l[i+1][1])
        print(sum(ans))


resolve()

Fixed submission:
import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    l = [0]*(n+1)
    l[n] = (A[n], A[n])
    for i in reversed(range(1, n+1)):
        l[i-1] = (max(math.ceil(l[i][0]/2)+A[i-1], 1), l[i][1]+A[i-1])

    if 1 not in range(l[0][0], l[0][1]+1):
        print(-1)
    else:
        ans = [0]*(n+1)
        ans[0] = 1
        cnt = 1
        for i in range(n):
            ans[i+1] = min((ans[i]-A[i])*2, l[i+1][1])
        print(sum(ans))


resolve()