Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
S = input()

sa = np.array([1 if i == "#" else 0 for i in S])
num = np.arange(N)
num_w = num[sa==0]
num_b = num[sa==1]
if len(num_w) == 0 or len(num_b) == 0:
    print(0)
    import sys
    sys.exit()
if num_b[-1] == N-1:
    w0 = 0
    w = len(num_w)
    b = np.sum([num_b<num_w[-1]])
else:
    w = np.sum([num_w<num_b[-1]])
    w0 = len(num_w) - w
    b = np.sum([num_b<num_w[num_w<num_b[-1]][-1]])
if w > b:
    print(b+w0)
else:
    print(w+w0)

Fixed submission:
N = int(input())
S = input()

s = [0 for _ in range(N+1)]
for i, x in enumerate(S):
    if x == "#":
        s[i+1] = s[i] + 1
    else:
        s[i+1] = s[i]
num = N
for i in range(N+1):
    w = s[i] - s[0]
    b = (N - i) - (s[N] - s[i])
    if w + b < num:
        num = w + b
print(num)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N, K = map(int, input().split(" "))
S = np.array([int(i) for i in input()])
pos1 = np.linspace(0,N-1,N)[S == 1]
lst = []
st =[pos1[0]]
for i in pos1[1:]:
    if st[-1] + 1 == i:
        st.append(i)
    else:
        lst.append(st)
        st = [i]
    if i == pos1[-1]:
        lst.append(st)
lst = [[0]] + lst + [[N-1]]
time = len(lst) - K
if time <= 0:
    print(N)
else:
    print(int(max([max(lst[i+K]) - min(lst[i])+1 for i in range(time)])))

Fixed submission:
import numpy as np

N, K = map(int, input().split(" "))
S = np.array([int(i) for i in input()])
pos1 = np.linspace(0,N-1,N)[S == 1]
lst = []
if len(pos1) == 0:
    print(N)
else:    
    st =[pos1[0]]
    if len(pos1) != 1:
        for i in pos1[1:]:
            if st[-1] + 1 == i:
                st.append(i)
            else:
                lst.append(st)
                st = [i]
            if i == pos1[-1]:
                lst.append(st)
    else:
        lst.append(st)
    lst = [[0]] + lst + [[N-1]]
    time = len(lst) - K
    if time <= 0:
        print(N)
    else:
        print(int(max([max(lst[i+K]) - min(lst[i])+1 for i in range(time)])))
Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys

N, Q = map(int, input().split(" "))
s = input()
alpha = [chr(i) for i in range(65, 65+N)]
s_lst = np.array([alpha.index(i) for i in s])
gol = np.ones_like(s_lst)

for i in range(Q):
    t_str, d = input().split(" ")
    t = alpha.index(t_str)
    move_from = (s_lst == t)
    gol_move = gol * move_from
    gol[move_from] = 0
    if d == "R":
        gol_add = np.hstack((np.array([0]), gol_move[:-1]))
    else:
        gol_add = np.hstack((gol_move[1:], np.array([0])))
    gol = gol + gol_add
print(np.sum(gol))
sys.stdout.flush()

Fixed submission:
import numpy as np
import sys

N, Q = map(int, input().split(" "))
s = [np.nan] + list(input()) + [np.nan]
td = [input().split(" ") for _ in range(Q)]

l = 0
r = N+1

for i, j in td[::-1]:
    if s[l+1] == i and j == "L":
        l += 1
    elif s[l] == i and j == "R":
        l -= 1
    if s[r-1] == i and j == "R":
        r -= 1
    elif s[r] == i and j =="L":
        r += 1
ln = max(0, l)
rn = max(0, N+1-r)
print(N-ln-rn)

Buggy python submission (verdict: Runtime Error):
import numpy as np

N, Q = map(int, input().split(" "))
s = input()
alpha = [chr(i) for i in range(65, 65+N)]
s_lst = np.array([alpha.index(i) for i in s])
gol = np.ones_like(s_lst)

for i in range(Q):
    t_str, d = input().split(" ")
    t = alpha.index(t_str)
    move_from = (s_lst == t)
    gol_move = gol * move_from
    gol[move_from] = 0
    if d == "R":
        gol_add = np.hstack((np.array([0]), gol_move[:-1]))
    else:
        gol_add = np.hstack((gol_move[1:], np.array([0])))
    gol = gol + gol_add
print(np.sum(gol))

Fixed submission:
import numpy as np
import sys

N, Q = map(int, input().split(" "))
s = [np.nan] + list(input()) + [np.nan]
td = [input().split(" ") for _ in range(Q)]

l = 0
r = N+1

for i, j in td[::-1]:
    if s[l+1] == i and j == "L":
        l += 1
    elif s[l] == i and j == "R":
        l -= 1
    if s[r-1] == i and j == "R":
        r -= 1
    elif s[r] == i and j =="L":
        r += 1
ln = max(0, l)
rn = max(0, N+1-r)
print(N-ln-rn)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split(" "))
S = input()
for _ in range(Q):
    l, r = map(int, input().split(" "))
    s = S[l-1:r]
    print(int((len(s)-len("".join(s.split("AC"))))/2))

Fixed submission:
N, Q = map(int, input().split(" "))
S = input()
t = [0] * (N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)
for i in range(Q):
    l, r = map(int, input().split(" "))
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split(" "))
S = input()
for _ in range(Q):
    l, r = map(int, input().split(" "))
    s = S[l-1:r]
    len_ss = 0
    for i in s.split("AC"):
        len_ss += len(i)
    print(int((len(s)-len_ss)/2))

Fixed submission:
N, Q = map(int, input().split(" "))
S = input()
t = [0] * (N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)
for i in range(Q):
    l, r = map(int, input().split(" "))
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
def ACGT(x):
    if x == "A":
        return 0
    if x == "C":
        return 1
    else:
        return 2

N, Q = map(int, input().split(" "))
S = np.array([ACGT(x) for x in input()])
lr = [[int(j) for j in input().split(" ")] for i in range(Q)]

ind = np.linspace(1,N,N)
posA = np.hstack((np.array([False]), (S == 0)[:-1]))
ind_cand = ind[posA]
posC = (S[posA] == 1)
indAC = ind_cand[posC]

for l, r in lr:
    print(np.sum(((indAC >= l+1) & (indAC <= r))))

Fixed submission:
N, Q = map(int, input().split(" "))
S = input()
t = [0] * (N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)
for i in range(Q):
    l, r = map(int, input().split(" "))
    print(t[r-1]-t[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, K = map(int, input().split(" "))
H = [int(i) for i in input().split(" ")]

cost = np.array([0] + [10**9 for _ in range(N-1)])
for i in range(1,N):
    for j in range(min(i, K)):
        cost[i] = np.min([cost[i], cost[i-j-1] + abs(H[i-j-1] - H[i])])

print(cost[-1])

Fixed submission:
import numpy as np
N, K = map(int, input().split(" "))
H = np.array([int(i) for i in input().split(" ")])

cost = np.array([0] + [10**9 for _ in range(N-1)])
for i in range(1,N):
    cost[i] = np.min(cost[max(0,i-K):i] + np.abs(H[max(0,i-K):i] - H[i]))

print(cost[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split(" "))
H = [int(i) for i in input().split(" ")]

cost = [0] + [10**9 for _ in range(N-1)]
for i in range(1,N):
    for j in range(min(i, K)):
        cost[i] = min(cost[i], cost[i-j-1] + abs(H[i-j-1] - H[i]))

print(cost[-1])

Fixed submission:
import numpy as np
N, K = map(int, input().split(" "))
H = np.array([int(i) for i in input().split(" ")])

cost = np.array([0] + [10**9 for _ in range(N-1)])
for i in range(1,N):
    cost[i] = np.min(cost[max(0,i-K):i] + np.abs(H[max(0,i-K):i] - H[i]))

print(cost[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split(" "))
H = [int(i) for i in input().split(" ")]

cost = [10**9 for _ in range(N)]
cost[0] = 0
for i in range(1,N):
    for j in range(min(i, K)):
        cost[i] = min(cost[i], cost[i-j-1] + abs(H[i-j-1] - H[i]))

print(cost[-1])

Fixed submission:
import numpy as np
N, K = map(int, input().split(" "))
H = np.array([int(i) for i in input().split(" ")])

cost = np.array([0] + [10**9 for _ in range(N-1)])
for i in range(1,N):
    cost[i] = np.min(cost[max(0,i-K):i] + np.abs(H[max(0,i-K):i] - H[i]))

print(cost[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split(" "))
H = [int(i) for i in input().split(" ")]

cost = [10**9 for _ in range(N)]
cost[0] = 0
for i in range(1,N):
    for j in range(min(i, K)):
        cand = cost[i-j-1] + abs(H[i-j-1] - H[i])
        if cost[i] > cand:
            cost[i] = cand
print(cost[-1])

Fixed submission:
import numpy as np
N, K = map(int, input().split(" "))
H = np.array([int(i) for i in input().split(" ")])

cost = np.array([0] + [10**9 for _ in range(N-1)])
for i in range(1,N):
    cost[i] = np.min(cost[max(0,i-K):i] + np.abs(H[max(0,i-K):i] - H[i]))

print(cost[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split(" "))
H = [int(i) for i in input().split(" ")]

cost = [0 for _ in range(N)]
for i in range(1,N):
    c_lst = [abs(H[i]-H[i-j-1])+cost[i-(j+1)] for j in range(min(K, i))]
    cost[i] = min(c_lst)
print(cost[-1])

Fixed submission:
import numpy as np
N, K = map(int, input().split(" "))
H = np.array([int(i) for i in input().split(" ")])

cost = np.array([0] + [10**9 for _ in range(N-1)])
for i in range(1,N):
    cost[i] = np.min(cost[max(0,i-K):i] + np.abs(H[max(0,i-K):i] - H[i]))

print(cost[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split(" "))
wv = [[int(i) for i in input().split(" ")] for _ in range(N)]

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if j - wv[i][0] >= 0:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j - wv[i][0]] + wv[i][1])
        
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
print(dp[N][W])

Fixed submission:
import numpy as np
N, W = map(int, input().split(" "))

dp = np.zeros(W+1,dtype=int)
for i in range(N):
    w,v = map(int, input().split(" "))
    dp[w:] = np.maximum(dp[w:], dp[:-w]+v)
print(int(dp[-1]))
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, W = map(int, input().split(" "))

dp = np.zeros(W+1,dtype=int)
for i in range(N):
    w,v = map(int, input().split(" "))
    dp[w:] = np.maximum(dp[w:], dp[:-w]+v)
print(int(dp[-1]))

Fixed submission:
import numpy as np
INF = 10 ** 12

N, W = map(int, input().split(" "))
wv = np.array([[int(i) for i in input().split(" ")] for _ in range(N)])

sumv = np.sum(wv[:,1])

dp = np.zeros((N + 1, sumv + 1), dtype=np.int64)
dp[0][1:] = INF

for i in range(N):
    dp[i+1][:wv[i][1]] = dp[i][:wv[i][1]]
    dp[i+1][wv[i][1]:] = np.minimum(dp[i][wv[i][1]:], dp[i][:-wv[i][1]]+wv[i][0])

ans = 0
for v, w in enumerate(dp[N]):
    if w <= W:
        ans = max(v, ans)

print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
N = len(T)

flag = False
pos = 51
ans = ""
for i in range(len(S)-4):
    cnt = 0
    for j in range(N):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
        else:
            break
    if cnt == N:
        pos = i
        flag = True
if flag:
    for i in range(len(S)):
        if pos <= i and i < pos + N:
            ans += T[i-pos]
        elif S[i] == "?":
            ans += "a"
        else:
            ans += S[i]
else:
    ans = "UNRESTORABLE"
print(ans)

Fixed submission:
S = input()
T = input()
N = len(T)

if len(S) < N:
    print("UNRESTORABLE")
    import sys
    sys.exit()

flag = False
pos = 51
ans = ""
for i in range(len(S)-N+1):
    cnt = 0
    for j in range(N):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
        else:
            break
    if cnt == N:
        pos = i
        flag = True
if flag:
    for i in range(len(S)):
        if pos <= i and i < pos + N:
            ans += T[i-pos]
        elif S[i] == "?":
            ans += "a"
        else:
            ans += S[i]
else:
    ans = "UNRESTORABLE"
print(ans)

Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
N = len(T)

flag = False
pos = 51
ans = ""
for i in range(len(S)-4):
    cnt = 0
    for j in range(N):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
        else:
            break
    if cnt == N:
        pos = i
        flag = True
        break
if flag:
    for i in range(len(S)):
        if pos <= i and i < pos + N:
            ans += T[i-pos]
        elif S[i] == "?":
            ans += "a"
        else:
            ans += S[i]
else:
    ans = "UNRESTORABLE"
print(ans)

Fixed submission:
S = input()
T = input()
N = len(T)

if len(S) < N:
    print("UNRESTORABLE")
    import sys
    sys.exit()

flag = False
pos = 51
ans = ""
for i in range(len(S)-N+1):
    cnt = 0
    for j in range(N):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
        else:
            break
    if cnt == N:
        pos = i
        flag = True
if flag:
    for i in range(len(S)):
        if pos <= i and i < pos + N:
            ans += T[i-pos]
        elif S[i] == "?":
            ans += "a"
        else:
            ans += S[i]
else:
    ans = "UNRESTORABLE"
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
lst = [A.count(a)%2 for a in set(A)]
print(sum(lst))

Fixed submission:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
As = sorted(A)
num = 0
i = 0
while i < N:
    count = 0
    j = As[i]
    while i < N and As[i] == j:
        count += 1
        i += 1
    if count % 2 == 1:
        num += 1
print(num)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [0 for _ in range(N)]
for i in range(N):
    A[i] = int(input())
lst = [A.count(a)%2 for a in set(A)]
print(sum(lst))

Fixed submission:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
As = sorted(A)
num = 0
i = 0
while i < N:
    count = 0
    j = As[i]
    while i < N and As[i] == j:
        count += 1
        i += 1
    if count % 2 == 1:
        num += 1
print(num)
Buggy python submission (verdict: Runtime Error):
N, C, K = map(int, input().split(" "))
T = sorted([int(input()) for _ in range(N)])

bus = 1
key = T[0]
pas = 0
for i in range(N):
    if T[i] - key > K:
        bus += 1
        key = T[i]
        pas = 0
    else:
        pas += 1
        if pas == C:
            bus += 1
            key = T[i+1]
            pas = 0
print(bus)

Fixed submission:
N, C, K = map(int, input().split(" "))
T = sorted([int(input()) for _ in range(N)])

bus = 0
i = 0
while i < N:
    bus += 1
    start = i
    while i < N and T[i] - T[start] <= K and i - start < C:
        i += 1
print(bus)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, C, K = map(int, input().split(" "))
T = np.sort([int(input()) for _ in range(N)])

i = 0
bus = 0
while i < N:
    bus += 1
    lst = T[i:i+C]
    i += len(lst[lst - lst[0] <= K])
print(bus)

Fixed submission:
N, C, K = map(int, input().split(" "))
T = sorted([int(input()) for _ in range(N)])

bus = 0
i = 0
while i < N:
    bus += 1
    start = i
    while i < N and T[i] - T[start] <= K and i - start < C:
        i += 1
print(bus)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, C, K = map(int, input().split(" "))
T = np.sort([int(input()) for _ in range(N)])

i = 0
j = C
bus = 0
while i < N:
    bus += 1
    lst = T[i:j]
    i += len(lst[lst - lst[0] <= K])
    j = i + C
print(bus)

Fixed submission:
N, C, K = map(int, input().split(" "))
T = sorted([int(input()) for _ in range(N)])

bus = 0
i = 0
while i < N:
    bus += 1
    start = i
    while i < N and T[i] - T[start] <= K and i - start < C:
        i += 1
print(bus)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
bottom = sum(A)

if N == 0:
  if A[0] != 1:
    print(-1)
  else:
    print(1)
  exit()
 
ret = 1
children = 1 - A[0]
bottom -= A[0]
 
for i in range(N):
    children = children * 2 - A[i+1]
    if children <= -1:
      ret = -1
      break
    
    bottom -= A[i+1]
    if children >= bottom:
      children = bottom
    ret += children + A[i+1]
print(ret)


Fixed submission:
h1, m1, h2, m2, k=map(int, input().split())

print((h2-h1)*60+(m2-m1)-k)

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

if A[0] >= 2:
  print(-1)
  exit()

ret = 1
children = 1 - A[0]
bottom -= A[0]
 
for i in range(N):
    children = children * 2 - A[i+1]
    if children <= -1:
      ret = -1
      break
    
    bottom -= A[i+1]
    if children >= bottom:
      children = bottom
    ret += children + A[i+1]
print(ret)


Fixed submission:
h1, m1, h2, m2, k=map(int, input().split())

print((h2-h1)*60+(m2-m1)-k)

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

if A[0] >= 2:
  print(-1)
  exit()

ret = 1
children = 1 - A[0]
bottom -= A[0]
 
for i in range(N):
    children = children * 2 - A[i+1]
    if children <= -1:
      ret = -1
      break
    
    bottom -= A[i+1]
    if children >= bottom:
      children = bottom
    ret += children + A[i+1]
print(ret)


Fixed submission:
h1, m1, h2, m2, k=map(int, input().split())

print((h2-h1)*60+(m2-m1)-k)

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

if A[0] >= 1:
  print(-1)
  exit()

ret = 1
children = 1

for i in range(N):
    children = children * 2 - A[i+1]
    if children <= -1:
      ret = -1
      break
    
    bottom -= A[i+1]
    if children >= bottom:
      children = bottom
    ret += children + A[i+1]
    print(children)
    print(bottom)
print(ret)

Fixed submission:
h1, m1, h2, m2, k=map(int, input().split())

print((h2-h1)*60+(m2-m1)-k)

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

ret = 1
children = 1 - A[0]
bottom -= A[0]

for i in range(N):
    children = children * 2 - A[i+1]
    if children <= -1:
      ret = -1
      break
    
    bottom -= A[i+1]
    if children >= bottom:
      children = bottom
    ret += children + A[i+1]
print(ret)


Fixed submission:
h1, m1, h2, m2, k=map(int, input().split())

print((h2-h1)*60+(m2-m1)-k)

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

ret = 1
children = 1 - A[0]
bottom -= A[0]

for i in range(N):
    children = children * 2 - A[i+1]
    if children <= 0:
      ret = -1
      break
    
    bottom -= A[i+1]
    if children >= bottom:
      children = bottom
    ret += children + A[i+1]
print(ret)


Fixed submission:
h1, m1, h2, m2, k=map(int, input().split())

print((h2-h1)*60+(m2-m1)-k)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
bottom = sum(A)

if A[0] >= 1 and N <> 1:
  print(-1)
  exit()

ret = 1
children = 1 - A[0]
bottom -= A[0]
 
for i in range(N):
    children = children * 2 - A[i+1]
    if children <= -1:
      ret = -1
      break
    
    bottom -= A[i+1]
    if children >= bottom:
      children = bottom
    ret += children + A[i+1]
print(ret)


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

if A[0] >= 2:
  print(-1)
  exit()

ret = 1
children = 1 - A[0]
bottom -= A[0]
 
for i in range(N):
    children = children * 2 - A[i+1]
    if children <= -1:
      ret = -1
      break
    
    bottom -= A[i+1]
    if children >= bottom:
      children = bottom
    ret += children + A[i+1]
print(ret)

Buggy python submission (verdict: Runtime Error):
32.txt

N = int(input())
A = list(map(int, input().split()))
bottom = sum(A)

if A[0] >= 1:
  print(-1)
  exit()

ret = 1
children = 1 - A[0]
bottom -= A[0]
 
for i in range(N):
    children = children * 2 - A[i+1]
    if children <= -1:
      ret = -1
      break
    
    bottom -= A[i+1]
    if children >= bottom:
      children = bottom
    ret += children + A[i+1]
print(ret)


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

if A[0] >= 2:
  print(-1)
  exit()

ret = 1
children = 1 - A[0]
bottom -= A[0]
 
for i in range(N):
    children = children * 2 - A[i+1]
    if children <= -1:
      ret = -1
      break
    
    bottom -= A[i+1]
    if children >= bottom:
      children = bottom
    ret += children + A[i+1]
print(ret)

Buggy python submission (verdict: Runtime Error):
if A[0] >= 1:
  print(-1)
else:
  print(1)

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

if A[0] >= 2:
  print(-1)
  exit()

ret = 1
children = 1 - A[0]
bottom -= A[0]
 
for i in range(N):
    children = children * 2 - A[i+1]
    if children <= -1:
      ret = -1
      break
    
    bottom -= A[i+1]
    if children >= bottom:
      children = bottom
    ret += children + A[i+1]
print(ret)

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

if A[0] >= 1:
  print(-1)
  exit()

ret = 1
children = 1

for i in range(N):
    children = children * 2 - A[i+1]
    if children <= -1:
      ret = -1
      break
    if children == 0 and i = N - 1:
      ret = -1
      break
    
    bottom -= A[i+1]
    if children >= bottom:
      children = bottom
    ret += children + A[i+1]
print(ret)

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

if A[0] >= 2:
  print(-1)
  exit()

ret = 1
children = 1 - A[0]
bottom -= A[0]
 
for i in range(N):
    children = children * 2 - A[i+1]
    if children <= -1:
      ret = -1
      break
    
    bottom -= A[i+1]
    if children >= bottom:
      children = bottom
    ret += children + A[i+1]
print(ret)
Buggy python submission (verdict: Runtime Error):
# coding:utf-8
readline = sys.stdin.buffer.readline
H1 = int(readline())
M1 = int(readline())
H2 = int(readline())
M2 = int(readline())
K = int(readline())
while not 0 <= H1 < 23 and 0 <= M1 < 59 and 0 <= H2 < 23 and 0 <= M2 < 59:
    H1 = int(readline())
    M1 = int(readline())
    H2 = int(readline())
    M2 = int(readline())
    K = int(readline())
if M2 > M1:
    a = (H2 - H1) * 60 + M2 - M1
    print(a - K)
if M2 < M1:
    b = (H2 - H1) * 60 + M1 - M2
    print(b - K)

Fixed submission:
import sys
readline = sys.stdin.buffer.readline
h1, m1, h2, m2, k = map(int, readline().split())
print(60 * (h2 - h1) + m2 - m1 - k)

Buggy python submission (verdict: Runtime Error):
# coding:utf-8
import readline
import datetime
readline = sys.stdin.buffer.readline
H1 = int(readline())
M1 = int(readline())
H2 = int(readline())
M2 = int(readline())
K = int(readline())
while not 0 <= H1 < 23 and 0 <= M1 < 59 and 0 <= H2 < 23 and 0 <= M2 < 59:
    H1 = int(readline())
    M1 = int(readline())
    H2 = int(readline())
    M2 = int(readline())
    K = int(readline())
if M2 > M1:
    a = (H2 - H1) * 60 + M2 - M1
    print(a - K)
if M2 < M1:
    b = (H2 - H1) * 60 + M1 - M2
    print(b - K)

Fixed submission:
import sys
readline = sys.stdin.buffer.readline
h1, m1, h2, m2, k = map(int, readline().split())
print(60 * (h2 - h1) + m2 - m1 - k)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
def main():
   N,M = map(int,input().split())
   Set = set()
   for i in range(M):
      a,b = map(int,input().split())
      Set.add((a,b))
      Set.add((b,a))                        #ADD
      for j in range(2,N):
         if (1,j) in Set and (j,N) in Set:
            print("POSSIBLE")
            return
   else:
       print("IMPOSSIBLE")

main()


Fixed submission:
import sys
input = sys.stdin.readline
def main():
   N,M = map(int,input().split())
   Set = set()
   for i in range(M):
      a,b = map(int,input().split())
      Set.add((a,b))
      Set.add((b,a))                        #condition
   for j in range(2,N):
      if (1,j) in Set and (j,N) in Set:
         print("POSSIBLE")
         return
   print("IMPOSSIBLE")

main()