Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def resolve():
    h, w  = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    ans = []
    for i in range(h):
        for j in range(w):
            if j != w-1 :
                if a[i][j] % 2 == 0:
                    continue
                else:
                    ans.append([i+1, j+1, i+1, j+2])
                    a[i][j+1] += 1
    for i in range(h):
        if i != h-1:
            if a[i][w-1] & 2 == 0:
                continue
            else:
                ans.append([i+1, j+1, i+2, j+1])
                a[i][j+1] += 1
    print(len(ans))
    for i in range(len(ans)):
        print(*ans[i])
resolve()

Fixed submission:

def resolve():
    h, w  = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    ans = []
    for i in range(h):
        for j in range(w):
            if j != w-1 :
                if a[i][j] % 2 == 0:
                    continue
                else:
                    ans.append([i+1, j+1, i+1, j+2])
                    a[i][j+1] += 1
                    a[i][j] -= 1
    for i in range(h):
        if i != h-1:
            if a[i][w-1] % 2 == 0:
                continue
            else:
                ans.append([i+1, j+1, i+2, j+1])
                a[i+1][w-1] += 1
                a[i][w-1] -= 1
    print(len(ans))
    for i in range(len(ans)):
        print(*ans[i])
resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():
    h, w  = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    ans = []
    for i in range(h):
        for j in range(w):
            if j != w-1 :
                if a[i][j] % 2 == 0:
                    continue
                else:
                    ans.append([i, j, i, j+1])
                    a[i][j+1] += 1
    for i in range(h):
        if i != h-1:
            if a[i][w-1] & 2 == 0:
                continue
            else:
                ans.append([i, j, i+1, j])
                a[i][j+1] += 1
    print(len(ans))
    for i in range(len(ans)):
        print(*ans[i])
resolve()

Fixed submission:

def resolve():
    h, w  = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    ans = []
    for i in range(h):
        for j in range(w):
            if j != w-1 :
                if a[i][j] % 2 == 0:
                    continue
                else:
                    ans.append([i+1, j+1, i+1, j+2])
                    a[i][j+1] += 1
                    a[i][j] -= 1
    for i in range(h):
        if i != h-1:
            if a[i][w-1] % 2 == 0:
                continue
            else:
                ans.append([i+1, j+1, i+2, j+1])
                a[i+1][w-1] += 1
                a[i][w-1] -= 1
    print(len(ans))
    for i in range(len(ans)):
        print(*ans[i])
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    lena = len(a)
    if (lena-k) % (k-1) == 0:
        print(((lena-k) // (k-1))+1)
    else :
        print(((lena-k) // (k-1))+2)
 resolve()

Fixed submission:
def resolve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    lena = len(a)
    if (lena-k) % (k-1) == 0:
        print(((lena-k) // (k-1))+1)
    else :
        print(((lena-k) // (k-1))+2)
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    a = [0, *a, 0]
    total = 0
    for i in range(1, len(a)):
        total += abs(a[i]-a[i-1])

    for i in range(1, len(a)-1):
        a1 = a[i-1]
        a2 = a[i]
        a3 = a[i+1]
        if a1 <= a2 <= a3 or a1 >= a2 >= a3:
            print(total)
        else:
            print(total-2*min(abs(a2-a1), abs(a3-a2)))
resolve()

Fixed submission:
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    a = [0]+a+[0]
    total = 0
    for i in range(1, len(a)):
        total += abs(a[i]-a[i-1])
 
    for i in range(1, len(a)-1):
        a1 = a[i-1]
        a2 = a[i]
        a3 = a[i+1]
        if a1 <= a2 <= a3 or a1 >= a2 >= a3:
            print(total)
        else:
            print(total-2*min(abs(a2-a1), abs(a3-a2)))
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    from collections import deque
    x = input()
    final = deque([])
    final.append(x[0])
    for i in range(1, len(x)):
        if x[i] == "S":
            final.append("S")
        else:
            last = final.pop()
            if last == "S":
                continue
            else:
                final.append("T")
                final.append("T")
    print(len(final))

resolve()

Fixed submission:
def resolve():
    from collections import deque
    x = input()
    final = deque([])
    final.append(x[0])
    for i in range(1, len(x)):
        if x[i] == "S":
            final.append("S")
        else:
            if not final:
                final.append("T")
            else:
                last = final.pop()
                if last == "S":
                    continue
                else:
                    final.append("T")
                    final.append("T")
    print(len(final))
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    import re
    x = input()
    while "ST" in x:
        x = re.sub("ST", "", x)
    print(len(x))
resolve()

Fixed submission:
def resolve():
    from collections import deque
    x = input()
    final = deque([])
    final.append(x[0])
    for i in range(1, len(x)):
        if x[i] == "S":
            final.append("S")
        else:
            if not final:
                final.append("T")
            else:
                last = final.pop()
                if last == "S":
                    continue
                else:
                    final.append("T")
                    final.append("T")
    print(len(final))
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

h, w = map(int, input().split())
c = [list(input()) for _ in range(h)]

q = deque([])

for i in range(h):
    for j in range(w):
        if c[i][j] == '#':
            q.append([i, j])
            c[i][j] = 0

p = q.popleft()
max = 0
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
while True:
    xx = p[0]
    yy = p[1]
    for i in range(4):
        x = xx + dx[i]
        y = yy + dy[i]
        if x < 0 or x > h - 1 or y < 0 or w - 1 < y:
            continue
        if c[x][y] == '.':
            q.append([x, y])
            count = c[xx][yy] + 1
            if max < count:
                max = count
            c[x][y] = count
    if len(q) == 0:
        break
    p = q.popleft()
print(max)


Fixed submission:
from collections import deque

h, w = map(int, input().split())
c = [list(input()) for _ in range(h)]

q = deque([])

for i in range(h):
    for j in range(w):
        if c[i][j] == '#':
            q.append([i, j])
            c[i][j] = 0

p = q.popleft()
max = 0
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
while True:
    xx = p[0]
    yy = p[1]
    for i in range(4):
        x = xx + dx[i]
        y = yy + dy[i]
        if x < 0 or x > h - 1 or y < 0 or w - 1 < y:
            continue
        if c[x][y] == '.':
            q.append([x, y])
            count = c[xx][yy] + 1
            if max < count:
                max = count
            c[x][y] = count
    if len(q) == 0:
        break
    p = q.popleft()
print(max)
Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
l = list(map(int, input().split()))
res = 1
flag = 0
for i in l:
	res *= i
	if i == 0:
		flag = 0
		res = 0
	if(res > 1000000000000000000):
		flag = 1
if flag == 1:
	print('-1')
else : print(res)


Fixed submission:

n = int(input())
l = list(map(int, input().split()))
res = 1
flag = 0
for i in l:
	res *= i
	if i == 0:
		flag = 0
		res = 0
	if(res > 1000000000000000000):
		flag = 1
		break
for i in l:
	if (i == 0):
		flag = 0
		res = 0
if flag == 1:
	print('-1')
else : print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = 1

for j in range(k):
    b *= a[j]

for i in range(1, n-k+1):
    c = b
    b *= a[k+i-1]
    b /= a[i-1]
    if b > c:
        print('Yes')
    else:
        print('No')




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

for i in range(1, n-k+1):
    if a[k+i-1] > a[i-1]:
        print('Yes')
    else:
        print('No')

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

for j in range(k):
    b *= a[j]

for i in range(1, n-k+1):
    c = b
    b *= a[k+i-1]
    b /= a[i-1]
    if b > c:
        print('Yes')
    else:
        print('No')




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

for i in range(1, n-k+1):
    if a[k+i-1] > a[i-1]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

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

for i in range(n):
    b *= a[i]
    
if b > 10 ** 18:
    b = -1

print(b)

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

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

for i in range(n):
    b *= a[i]
    if b > 10 ** 18:
        b = -1
        break

for i in range(n):
    if a[i] == 0:
        b = 0

print(b)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
b = 1
mod = 10**9+7

for i in range(n):
        b *= a[i]

if b > 10 ** 18:
    print(-1)
else:
    print(b)

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

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

for i in range(n):
    b *= a[i]
    if b > 10 ** 18:
        b = -1
        break

for i in range(n):
    if a[i] == 0:
        b = 0

print(b)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
b = 1
mod = 10**9+7

for i in range(n):
        b *= a[i]

if b > 10 ** 18:
    print(-1)
else:
    print(b)

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

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

for i in range(n):
    b *= a[i]
    if b > 10 ** 18:
        b = -1
        break

for i in range(n):
    if a[i] == 0:
        b = 0

print(b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = 1

for i in range(n):
    b *= a[i]

if b > 10 ** 18:
    print(-1)
else:
    print(b)

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

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

for i in range(n):
    b *= a[i]
    if b > 10 ** 18:
        b = -1
        break

for i in range(n):
    if a[i] == 0:
        b = 0

print(b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = 1

for i in range(n):
    b *= a[i]

if b > 10 ** 18:
    print(-1)
else:
    print(b)

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

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

for i in range(n):
    b *= a[i]
    if b > 10 ** 18:
        b = -1
        break

for i in range(n):
    if a[i] == 0:
        b = 0

print(b)
Buggy python submission (verdict: Runtime Error):
t = list(input())

if t[0] == '?' and t[1] == 'D':
    t[0] = 'P'
elif t[0] == '?' and t[1] == 'P':
    t[0] = 'D'
elif t[0] == '?' and t[1] == '?':
    t[0] = 'P'

for i in range(len(t)):
    if t[i] == '?' and t[i-1] =='P':
        t[i] = 'D'
    elif t[i] == '?' and t[i-1] =='D':
        t[i] = 'P'



print(''.join(t))

Fixed submission:
t = input()

print(t.replace('?', 'D'))

Buggy python submission (verdict: Runtime Error):
t = list(input())

for i in range(len(t)):
    if t[i] == '?' and t[i-1] =='P':
        t[i] = 'D'
    elif t[i] == '?' and t[i+1] =='D':
        t[i] = 'P'
    elif t[i] == '?' and t[i+1] =='?':
        t[i] = 'P'
        t[i+1] = 'D'

print(''.join(t))

Fixed submission:
t = input()

print(t.replace('?', 'D'))
Buggy python submission (verdict: Runtime Error):
R = int.input()
print(R*2*3.14)

Fixed submission:
print(int(input())*2*3.14)

Buggy python submission (verdict: Runtime Error):
R = input()
print(R*2*3.14)

Fixed submission:
print(int(input())*2*3.14)

Buggy python submission (verdict: Runtime Error):
R = input()
print(R*2*pi)

Fixed submission:
print(int(input())*2*3.14)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a * b % 2 == 0:
    print("Even")
elif:
    print("Odd")
    

Fixed submission:
a, b = map(int, input().split())
if a * b % 2 == 0:
    print("Even")
else:
    print("Odd")
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
print(math.ceil((A+B)/2))

Fixed submission:
import math
A, B = map(int, input().split())
print(math.ceil((A+B)/2))
Buggy python submission (verdict: Runtime Error):
for i in range(n):
    a.append(int(input())-1)

button = 0
cnt = 0
done = [False] * n

while True:
    if done[button] == False:
        done[button] = True
        cnt += 1
        if a[button] == 1:
            break
        button = a[button]
    else:
        cnt = -1
        break

print(cnt)

Fixed submission:
n = int(input())
a = []

for i in range(n):
    a.append(int(input())-1)

button = 0
cnt = 0
done = [False] * n

while True:
    if done[button] == False:
        done[button] = True
        cnt += 1
        if a[button] == 1:
            break
        button = a[button]
    else:
        cnt = -1
        break

print(cnt)
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())

a = []
b = list([['#']*(w+2)]*(h+2)) #[]で囲うことが重要


for i in range(h):
    a.append(list(input())) #splitを入れなければOK

for j in range(h):
    for k in range(w):
    b[j+1][k+1] = a[j][k]

print(b)


Fixed submission:
h, w = map(int, input().split())

sh = '#'

print(sh * (w+2))
[print(sh + input() + sh) for i in range(h)]
print(sh * (w+2))

Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())

a = []
b = list([['#']*(w+2)]*(h+2)) #[]で囲うことが重要


for i in range(h):
    a.append(list(input())) #splitを入れなければOK

for j in range(h):
    for k in range(w)
    b[j+1][k+1] = a[j][k]

print(b)

Fixed submission:
h, w = map(int, input().split())

sh = '#'

print(sh * (w+2))
[print(sh + input() + sh) for i in range(h)]
print(sh * (w+2))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return False
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
        return True

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

uf = UnionFind(N)
for _ in range(M):
    a, b = map(int, input().split())
    uf.union(a, b)
print(sum(x < 0 for x in uf.parents)-1)

Fixed submission:
N, M = map(int, input().split())

class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return False
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
        return True

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

uf = UnionFind(N)
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.union(a, b)
print(sum(x < 0 for x in uf.parents)-1)
Buggy python submission (verdict: Time Limit Exceeded):
N, X, M = map(int, input().split())
A = [[0] * (10**5+1) for _ in range(34)]
B = [[0] * (10**5+1) for _ in range(34)]

for i in range(10**5+1):
    A[0][i] = B[0][i] = i**2 % M
for i in range(33):
    for j in range(10**5+1):
        A[i+1][j] = A[i][A[i][j]]
        B[i+1][j] += B[i][j] + B[i][A[i][j]]
now = X
ans = X
i = 0
N -= 1
while N > 0:
    if N & 1:
        ans += B[i][now] 
        now = A[i][now]
    N >>= 1
    i += 1
print(ans)

Fixed submission:
N, X, M = map(int, input().split())
A = [[0] * (10**5+1) for _ in range(34)]
B = [[0] * (10**5+1) for _ in range(34)]

for i in range(10**5+1):
    A[0][i] = B[0][i] = i**2 % M
for i in range(33):
    for j in range(10**5+1):
        A[i+1][j] = A[i][A[i][j]]
        B[i+1][j] += B[i][j] + B[i][A[i][j]]
now = X
ans = X
i = 0
N -= 1
while N > 0:
    if N & 1:
        ans += B[i][now] 
        now = A[i][now]
    N >>= 1
    i += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

if K % 2 == 0:
    print(-1)
    exit()
rest = 7 % K
x = rest
ans = 1
while rest:
    ans += 1
    x = x*10 % K
    rest = (rest + x) % K
print(ans)

Fixed submission:
K = int(input())

if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()
rest = 7 % K
x = rest
ans = 1
while rest:
    ans += 1
    x = x*10 % K
    rest = (rest + x) % K
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

def f(x):
    ret = 0
    for a in A:
        ret += a//x
    return ret

if K == 0:
    print(max(A))
    exit()
ok = -1
ng = 10**9 + 1
while ng - ok > 1:
    mid = (ok + ng) // 2
    if f(mid) <= K:
        ng = mid
    else:
        ok = mid
print(ng)

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

def f(x):
    return sum((a+x-1)//x - 1 for a in A)

l = 0
r = 10**9+1 
while r - l > 1:
    mid = (l + r) // 2
    if f(mid) <= K:
        r = mid
    else:
        l = mid
print(r)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

def f(x):
    ret = 0
    for a in A:
        ret += a//x
    return ret

if K == 0:
    print(max(A))
    exit()
ok = -1
ng = 10**9 + 1
while ng - ok > 1:
    mid = (ok + ng) // 2
    if f(mid) <= K:
        ng = mid
    else:
        ok = mid
print(ng)

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

def f(x):
    return sum((a+x-1)//x - 1 for a in A)

l = 0
r = 10**9+1 
while r - l > 1:
    mid = (l + r) // 2
    if f(mid) <= K:
        r = mid
    else:
        l = mid
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
N , K = map(int, input().split())
A = list(map(int, input().split()))

x = 1
for a in A[:K]:
    x *= a
for i in range(K, N):
    xx = x // A[i-K] * A[i]
    if xx > x:
        print('Yes')
    else:
        print('No')
    x = xx

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

for i in range(K, N):
    x = A[i] / A[i-K]
    if x > 1:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())

    dp = [1] * (N+1)
    for i in range(2, N+1):
        for j in range(i, N+1, i):
            dp[j] = dp[j] + 1
    ans = 0
    for i in range(1, N+1):
        ans = ans + dp[i] * i
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N = int(input())

    dp = [1] * (N+1)
    for i in range(2, N+1):
        for j in range(i, N+1, i):
            dp[j] = dp[j] + 1
    ans = 0
    for i in range(1, N+1):
        ans = ans + dp[i] * i
    print(ans)

main()
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate

N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(min(K, 100)):
    tmp = [0]*N
    for i, ai in enumerate(A):
        tmp[max(0, i-ai)] += 1
        if i+ai+1 < N:
            tmp[i+ai+1] -= 1
    A = accumulate(tmp)
print(*A)


Fixed submission:
from itertools import accumulate

N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(min(K, 100)):
    tmp = [0]*N
    for i, ai in enumerate(A):
        tmp[max(0, i-ai)] += 1
        if i+ai+1 < N:
            tmp[i+ai+1] -= 1
    A = accumulate(tmp)
print(*A)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 1
inf = 10 ** 18
for a in A:
    ans *= a
if ans > inf:
    print(-1)
    exit()
print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = 1
inf = 10 ** 18
if 0 in A:
    print(0)
    exit()
for a in A:
    ans *= a
    if ans > inf:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

d = [1] * (N+1)
d[0] -= A[0]
for i in range(N):
    d[i+1] = d[i] * 2 - A[i+1]

if d[-1] < 0:
    print(-1)
    exit()
else:
    d[-1] = A[-1]
for i in range(N, 0, -1):
    x = d[i]
    x += A[i-1]
    if d[i-1] * 2 < x:
        y = x - A[i-1]
        if (y+1) // 2 + A[i-1] <= d[i-1] * 2:
            x = d[i-1] * 2
        else:
            print(-1)
            print(aaa)
            exit()
    d[i-1] = min(x, d[i-1]+A[i-1])
print(sum(d))


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

d = [1] * (N+1)
d[0] -= A[0]
for i in range(N):
    d[i+1] = d[i] * 2 - A[i+1]

if d[-1] < 0:
    print(-1)
    exit()
else:
    d[-1] = A[-1]
for i in range(N, 0, -1):
    x = d[i]
    x += A[i-1]
    if d[i-1] * 2 < x:
        y = x - A[i-1]
        if (y+1) // 2 + A[i-1] <= d[i-1] * 2:
            x = d[i-1] * 2
    d[i-1] = min(x, d[i-1]+A[i-1])
print(sum(d))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

d = [1] * (N+1)
d[0] -= A[0]
for i in range(N):
    d[i+1] = d[i] * 2 - A[i+1]

if d[-1] < 0:
    print(-1)
    print(aaaaaaa)
    exit()
else:
    d[-1] = A[-1]
for i in range(N, 0, -1):
    x = d[i]
    x += A[i-1]
    if d[i-1] * 2 < x:
        y = x - A[i-1]
        if (y+1) // 2 + A[i-1] <= d[i-1] * 2:
            x = d[i-1] * 2
    if d[i-1]*2 < x:
        print(-1)
        print(aaaaaaa)
        exit()
    d[i-1] = min(x, d[i-1]+A[i-1])
# print(d)
print(sum(d))


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

d = [1] * (N+1)
d[0] -= A[0]
for i in range(N):
    d[i+1] = d[i] * 2 - A[i+1]

if d[-1] < 0:
    print(-1)
    exit()
else:
    d[-1] = A[-1]
for i in range(N, 0, -1):
    x = d[i]
    x += A[i-1]
    if d[i-1] * 2 < x:
        y = x - A[i-1]
        if (y+1) // 2 + A[i-1] <= d[i-1] * 2:
            x = d[i-1] * 2
    d[i-1] = min(x, d[i-1]+A[i-1])
print(sum(d))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

d = [1] * (N+1)
d[0] -= A[0]
for i in range(N):
    d[i+1] = d[i] * 2 - A[i+1]

if d[-1] < 0:
    print(-1)
    print(aaaaaaa)
    exit()
else:
    d[-1] = A[-1]
for i in range(N, 0, -1):
    x = d[i]
    x += A[i-1]
    if d[i-1] * 2 < x:
        y = x - A[i-1]
        if (y+1) // 2 + A[i-1] <= d[i-1] * 2:
            x = d[i-1] * 2
    if d[i-1]*2 < x:
        print(-1)
        print(aaaaaaa)
        exit()
    d[i-1] = min(x, d[i-1]+A[i-1])
print(d)
print(sum(d))


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

d = [1] * (N+1)
d[0] -= A[0]
for i in range(N):
    d[i+1] = d[i] * 2 - A[i+1]

if d[-1] < 0:
    print(-1)
    exit()
else:
    d[-1] = A[-1]
for i in range(N, 0, -1):
    x = d[i]
    x += A[i-1]
    if d[i-1] * 2 < x:
        y = x - A[i-1]
        if (y+1) // 2 + A[i-1] <= d[i-1] * 2:
            x = d[i-1] * 2
    d[i-1] = min(x, d[i-1]+A[i-1])
print(sum(d))