Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve():
    S = Scanner.string()
    T = Scanner.string()
    ma = len(S) - len(T) + 1
    ans = len(T)
    for i in range(0, ma):
        cnt = 0
        for j in range(len(T)):
            if S[i + j] != T[j]:
                cnt += 1
        ans = min(ans, cnt)
    print(ans)


def main():
    # sys.setrecursionlimit(1000000)
    sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve():
    S = Scanner.string()
    T = Scanner.string()
    ma = len(S) - len(T) + 1
    ans = len(T)
    for i in range(0, ma):
        cnt = 0
        for j in range(len(T)):
            if S[i + j] != T[j]:
                cnt += 1
        ans = min(ans, cnt)
    print(ans)


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve():
    N, K = Scanner.map_int()
    A = Scanner.map_int()
    S = 1
    for i in range(K - 1):
        S *= A[i]
    for i in range(K, N):
        if A[i - K] < A[i]:
            print('Yes')
        else:
            print('No')


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve():
    N, K = Scanner.map_int()
    A = Scanner.map_int()
    for i in range(K, N):
        if A[i - K] < A[i]:
            print('Yes')
        else:
            print('No')


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    N = cin.int()
    A = cin.mapInt()
    T = [0] * N
    for i in range(N): 
        T[A[i] - 1] = i + 1
    print(*T," ")
    return

if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    N = cin.int()
    A = cin.mapInt()
    T = [0] * N
    for i in range(N): 
        T[A[i] - 1] = i + 1
    print(*T,sep =" ")
    return

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x

N,X = cin.mapInt()
A = cin.mapInt()
A.append(X)

def solve():
    A.sort()
    subs = [0] * (N)
    for i in range(N):
        subs[i] = A[i + 1] - A[i]
    ans = subs[0]
    for i in range(1,N - 1):
        ans = math.gcd(ans,subs[i])
    return ans
print(solve())


Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

N,X = cin.mapInt()
A = cin.mapInt()
A.append(X)

def solve():
    A.sort()
    subs = [0] * (N)
    for i in range(N):
        subs[i] = A[i + 1] - A[i]
    ans = subs[0]
    for i in range(1,N):
        ans = Math.gcd(ans,subs[i])
    return ans
print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

def solve() :
    X,Y = [int(x) for x in stdin.readline().rstrip().split()]

    if X == Y :
        print("-1")
        return
    
    ans = X * 2
    while True:
        if ans % Y != 0 :
            print(ans)
            return
        elif ans >= 1e18:
            print(-1)
            return
        else:
            ans += X

solve();

Fixed submission:
from sys import stdin

def solve() :
    X,Y = [int(x) for x in stdin.readline().rstrip().split()]

    if(X % Y != 0):
        print(X)
    else :
        print(-1)

solve();
Buggy python submission (verdict: Runtime Error):
from sys import stdin

def readString() :
    return  stdin.readline().rstrip()

def solve() :
    H,W = [int(x) for x in stdin.readline().rstrip().split()]

    table = [stdin.readline().rstrip().split() for _ in range(H)]

    l = [x for x in "ABCDEFGHIJK"]
    for h in range(0,H) :
        for w in range(0,W) :
            if(table[h][w] == "snuke"):
                print(l[w] + "" + str(h + 1))
solve();

Fixed submission:
from sys import stdin

def readString() :
    return  stdin.readline().rstrip()

def solve() :
    H,W = [int(x) for x in stdin.readline().rstrip().split()]

    table = [stdin.readline().rstrip().split() for _ in range(H)]

    l = [chr(i) for i in range(65, 65+26)]
    for h in range(0,H) :
        for w in range(0,W) :
            if(table[h][w] == "snuke"):
                print(l[w] + "" + str(h + 1))
solve();
Buggy python submission (verdict: Runtime Error):
A = map(int,input().split())
sorted(A)

if A[0] == 5 and A[1] == 5 and A[2] == 7:
    print("YES")
else:
    print("NO")


Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    A = Scanner.map_int()
    d = defaultdict(int)
    for a in A:
        d[a] += 1
    print('YNEOS'[not (d[5] == 2 and d[7] == 1)::2])


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

x, k, d = map(int, input().split())
dp = [None]*(1000000)
dp[0] = x

for i in range(1, k+1):
  x0, x1 = x+d, x-d
  if abs(x0) < abs(x1):
    x = x0
    dp[i] = x0
  else:
    x = x1
    dp[i] = x1
  if x == dp[i-2]:
    if i%2 != k%2:
      x = dp[i-1]
    break

print(abs(x))

Fixed submission:
import sys
input = sys.stdin.readline

x, k, d = map(int, input().split())
tmp = abs(x) // d

if k < tmp:
  result = abs(abs(x) - d*k)
elif tmp%2 == k%2:
  result = abs(abs(x) - d*tmp)
else:
  a = result = abs(abs(x) - d*tmp)
  result = abs(abs(a) - d)

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())

if k % 2 == 0:
  print("-1")
  quit()

num = 1
cnt = 1
if k % 7 ==0:
  k = k//7

while True:
  num = num % k
  if num == 0:
    print(cnt)
    break
  else:
    num += pow(10, cnt, k)
    cnt += 1
  

Fixed submission:
def main(k):
  if k % 2 == 0:
    return -1

  num = 1
  cnt = 1
  if k % 7 == 0:
    k = k//7

  for i in range(1000000):
    num = num % k
    if num == 0:
      return cnt
    else:
      num += pow(10, cnt, k)
      cnt += 1
  return -1

k = int(input())
print(main(k))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
arr = list(map(int, input().split()))

score = 1
for i in range(k):
  score *= arr[i]

s = 0

for i in range(k, n):
  tmp = score * arr[i] // arr[s]
  if tmp > score:
    print("Yes")
  else:
    print("No")
  score = tmp
  s += 1

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

s = 0

for i in range(k, n):
  before = arr[s]
  after = arr[i]
  if after > before:
    print("Yes")
  else:
    print("No")
  s += 1

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
arr = list(map(int, input().split()))

score = 1
for i in range(k):
  score *= arr[i]

s = 0

for i in range(k, n):
  tmp = score * arr[i] / arr[s]
  if tmp > score:
    print("Yes")
  else:
    print("No")
  score = tmp
  s += 1

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

s = 0

for i in range(k, n):
  before = arr[s]
  after = arr[i]
  if after > before:
    print("Yes")
  else:
    print("No")
  s += 1
Buggy python submission (verdict: Runtime Error):
l, r, d = map(int, input().split())

for i in range(l, r+1):
  if i % d == 0:
    minimum = i
    break

for i in range(r, l-1, -1):
  if i % d == 0:
    maximum = i
    break

print(int((maximum - minimum) / d + 1))

Fixed submission:
l, r, d = map(int, input().split())

count = 0
for i in range(l, r+1):
  if i % d == 0:
    count += 1

print(count)

Buggy python submission (verdict: Runtime Error):
l, r, d = map(int, input().split())

for i in range(l, r+1):
  if i % d == 0:
    minimum = i
    break

for i in range(r, l-1, -1):
  if i % d == 0:
    maximum = i
    break

print(int((maximum - minimum) / d + 1))
  

Fixed submission:
l, r, d = map(int, input().split())

count = 0
for i in range(l, r+1):
  if i % d == 0:
    count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, d = map(int, input().split())

max = a * c
for i in range(a, b+1):
  for j in range(c, d+1):
    k = i * j
    if k > max:
      max = k
      
print(max)

Fixed submission:
a, b, c, d = map(int, input().split())

e = a * c
f = a * d
g = b * c
h = b * d

list1 = [e, f, g, h]
max = max(list1)
print(max)
Buggy python submission (verdict: Runtime Error):
D, T, S = map(int, input())
if D <= T * S:
  print('Yes')
else:
  print('No')

Fixed submission:
D, T, S = map(int, input().split())
if D <= T * S:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
D, T, S = map(int, input())
if D >= T * S:
  print(Yes)
else:
  print(No)
  
  

Fixed submission:
D, T, S = map(int, input().split())
if D <= T * S:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
bool a = input()
print(!a)

Fixed submission:
a = int(input())
print(int(not a))

Buggy python submission (verdict: Runtime Error):
print(!(int)(input()))

Fixed submission:
a = int(input())
print(int(not a))

Buggy python submission (verdict: Runtime Error):
print(!input())

Fixed submission:
a = int(input())
print(int(not a))
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(m):
    m-=a[i]
if m>=0:
    print m
else:
    print -1

Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(m):
    n-=a[i]
if n>=0:
    print (n)
else:
    print (-1)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(0)]*n
l=list(map(int,input.().split()))
for i in range(n-1):
	a[l[i]] = a[l[i]] + 1
for i in range(n):
	print(a[i])
    

Fixed submission:
n=int(input())
a=[int(0)]*n
l=list(map(int,input().split()))
for i in range(n-1):
	a[l[i]-1] = a[l[i]-1] + 1
for i in range(n):
	print(a[i])
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())

tmp = 7
ans = -1
for i in range(1,10**6):  
  if tmp % k == 0:
    ans = i
    break
  tmp *= 10
  tmp += 7
print(ans)    

Fixed submission:
k = int(input())

tmp = 7
ans = -1
for i in range(1,10**6):  
  if tmp % k == 0:
    ans = i
    break
  tmp *= 10
  tmp = (tmp+7) % k
print(ans)
Buggy python submission (verdict: Runtime Error):
a = input()
print(a + a**2 + a**3)

Fixed submission:
a = int(input())
print(a + a**2 + a**3)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))
A = sorted(A)

limit = 10**6 + 2
A += [limit]
dp = [True] * (limit)

ans = 0
for i in range(n):
  a = A[i]
  if dp[a] and a != A[i+1]:
    ans += 1

  for t in range(a,limit,a):    
    dp[t] = False
    t += a

print(ans)    

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

limit = 10**6 + 2
A += [limit]
dp = [True] * (limit)

ans = 0
for i in range(n):
  a = A[i]
  if dp[a] and a != A[i+1]:
    ans += 1
  
  if dp[a] == False:
    continue
  for t in range(a,limit,a):    
    dp[t] = False
    t += a

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
A = list(map(int,input().split()))
A = sorted(A)

def divisors(n):
  ret=[]
  for i in range(1,int(n**0.5)+1):
    if n%i==0:
      ret.append(i)
      if n//i!=i:
        ret.append(n//i)
  return ret

s = set()
for a in A:
  dv = divisors(a)
  for d in dv:
    if d in s:  
      break
  else:
    s.add(a)
      
ans = 0
C = Counter(A)
for si in s:
  if C[si]==1:
    ans += 1
print(ans)          

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

limit = 10**6 + 2
A += [limit]
dp = [True] * (limit)

ans = 0
for i in range(n):
  a = A[i]
  if dp[a] and a != A[i+1]:
    ans += 1
  
  if dp[a] == False:
    continue
  for t in range(a,limit,a):    
    dp[t] = False
    t += a

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
A = list(map(int,input().split()))
A = sorted(A)

s = set()
for a in A:
  for si in s:
    if a%si==0:
      break
  else:
    s.add(a)
      
ans = 0
C = Counter(A)
for si in s:
  if C[si]==1:
    ans += 1
print(ans)          

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

limit = 10**6 + 2
A += [limit]
dp = [True] * (limit)

ans = 0
for i in range(n):
  a = A[i]
  if dp[a] and a != A[i+1]:
    ans += 1
  
  if dp[a] == False:
    continue
  for t in range(a,limit,a):    
    dp[t] = False
    t += a

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
A = list(map(int,input().split()))

for j in range(min(k,45)):
  B = [0]*(n)
  for i in range(n):
    l = max(0,i-A[i])
    r = min(n-1,i+A[i])
    B[l] += 1
    if r+1 < n:
      B[r+1] -= 1  
      
  for i in range(1,n):
    B[i]+=B[i-1]
  
  A = B.copy()
print(*B)  

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

for j in range(min(k,45)):
  B = [0]*(n)
  for i in range(n):
    l = max(0,i-A[i])
    r = min(n-1,i+A[i])
    B[l] += 1
    if r+1 < n:
      B[r+1] -= 1  
      
  for i in range(1,n):
    B[i]+=B[i-1]
  
  A = B.copy()
print(*B)

Buggy python submission (verdict: Time Limit Exceeded):
# 解説参照
n,k = map(int,input().split())
A = list(map(int,input().split()))

for j in range(min(k,41)):
  B = [0]*(n)
  for i in range(n):
    l = max(0,i-A[i])
    r = min(n-1,i+A[i])
    B[l] += 1
    if r+1 < n:
      B[r+1] -= 1  
      
  for i in range(1,n):
    B[i]+=B[i-1]
  
  A = B.copy()
print(*B)  

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

for j in range(min(k,45)):
  B = [0]*(n)
  for i in range(n):
    l = max(0,i-A[i])
    r = min(n-1,i+A[i])
    B[l] += 1
    if r+1 < n:
      B[r+1] -= 1  
      
  for i in range(1,n):
    B[i]+=B[i-1]
  
  A = B.copy()
print(*B)
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))

L = [0]*(n+2)
R = [0]*(n+2)

for i in range(n,-1,-1):
  L[i] = A[i] + (L[i+1]+1)//2
  R[i] = A[i] + R[i+1]
  
if L[0] > 1:
  print(-1)
else:
  ans = 0
  tmp = 1
  for i in range(n+1):
    ans += tmp          
    tmp -= A[i]    
    tmp = min(tmp*2,R[i+1])
    
print(ans)    

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

L = [0]*(n+2)
R = [0]*(n+2)
L[n] = A[n]
R[n] = A[n]

for i in range(n,-1,-1):
  L[i] = A[i] + (L[i+1]+1)//2
  R[i] = A[i] + R[i+1]
  
if L[0]>1:
  print(-1)
else:
  tmp = 1
  ans = 0
  for i in range(n+1):
    ans += tmp
    tmp -= A[i]
    tmp = min(tmp*2,R[i+1])    
  print(ans)