Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02684 (python)

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
done=[-1 for _ in range(N)]
done[0]=0
n=0
now=0
init=0
loop=N
log=[0]

while n<N:
    log.append(A[log[-1]]-1)
    n+=1
    if done[log[-1]]>-1:
        init=done[log[-1]]
        loop=n-done[log[-1]]
        break
    done[log[-1]]=n

if K<init:
    print(log[K]+1)
else:
    num=init+(K-init)%loop
    print(log[num]+1)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))
done=[0 for _ in range(N)]
done[0]=1
W=[0]
loop=0
city=0

for i in range(N):
    if done[A[i]-1]==2:
        init=W.index(A[i]-1)
        loop=i-init
        break
    elif city==A[city]-1:
        init=i
        loop=1
        break
    city=A[city]-1
    W.append(city)
    done[city]+=1

if min(done)>0:
    init=0
    loop=N

print(W[(K-init)%loop+init]+1)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))
done=[0 for _ in range(N)]
done[0]=1
W=[0]
loop=0
city=0
for i in range(N):
    if done[A[i]-1]==2:
        init=W.index(A[i]-1)
        loop=i-init
        break
    city=A[city]-1
    W.append(city)
    done[city]+=1

if min(done)>0:
    init=0
    loop=N

print(W[(K-init)%loop+init]+1)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))
done=[0 for _ in range(N)]
done[0]=1
W=[0]
loop=0
city=0
for i in range(N):
    if done[A[i]-1]==2:
        init=W.index(A[i]-1)
        loop=i-init
        break
    city=A[city]-1
    W.append(city)
    done[city]+=1

print(W[(K-init)%loop+init]+1)
Problem p02690 (python)

Fixed submission:
X=int(input())

for i in range(-1000,1000):
    for j in range(-1000,1000):
        if i**5==j**5+X:
            A=i
            B=j
            break
print(A,B)

Buggy submission (verdict: Runtime Error):
X=int(input())

for i in range(-100,100):
    for j in range(-100,100):
        if i**5==j**5+X:
            A=i
            B=j
            break
print(A,B)
Problem p02720 (python)

Fixed submission:
K=int(input())
if K<10:
    n=2
    i=1
else:
    n=10
    i=9
while i<K:
    S=str(n)
    cond=True
    for j in range(len(S)-1):
        if abs(int(S[j])-int(S[j+1]))>1:
            cond=False
            break
    if cond:
        i+=1
#        print(n)
        n+=1
    else:
        n+=10**(len(S)-j-2)
#        print(n,10**(len(S)-j-2))
print(n-1)

Buggy submission (verdict: Runtime Error):
K=int(input())
if K<10:
    print(K)
else:
    n=10
    i=9
while i<K:
    S=str(n)
    cond=True
    for j in range(len(S)-1):
        if abs(int(S[j])-int(S[j+1]))>1:
            cond=False
            break
    if cond:
        i+=1
#        print(n)
        n+=1
    else:
        n+=10**(len(S)-j-2)
#        print(n,10**(len(S)-j-2))
        
print(n-1)
Problem p02721 (python)

Fixed submission:
N,K,C=map(int,input().split())
SL=input()
SR=SL[::-1]
Left=[]
Right=[]
Last=-N-1
Rast=-N-1
cL=cR=0
for i in range(N):
    if SL[i]=="o" and i-Last>C and cL<=K:
        Left.append(i)
        Last=i
        cL+=1
    if SR[i]=="o" and i-Rast>C and cR<=K:
        Right.append(N-i-1)
        Rast=i
        cR+=1
Right=Right[::-1]

ans=[]
for k in range(K):
    if Left[k]==Right[k]:
        ans.append(Left[k]+1)

if len(ans)==0:
    print()
else:
    for a in ans:
        print(a)

Buggy submission (verdict: Runtime Error):
N,K,C=map(int,input().split())
SL=input()
SR=SL[::-1]
Left=[]
Right=[]
Last=-N
Rast=-N
cL=cR=0
for i in range(N):
    if SL[i]=="o" and i-Last>C and cL<=K:
        Left.append(i)
        Last=i
        cL+=1
    if SR[i]=="o" and i-Rast>C and cR<=K:
        Right.append(N-i-1)
        Rast=i
        cR+=1
Right=Right[::-1]

ans=[]

for k in range(K):
    if Left[k]==Right[k]:
        ans.append(Left[k]+1)

if len(ans)==0:
    print()
else:
    for a in ans:
        print(a)

Buggy submission (verdict: Runtime Error):
N,K,C=map(int,input().split())
SL=input()
SR=SL[::-1]
Left=[]
Right=[]
Last=-N
Rast=-N
cL=cR=0
for i in range(N):
    if SL[i]=="o" and i-Last>C and cL<=K:
        Left.append(i)
        Last=i
        cL+=1
    if SR[i]=="o" and i-Rast>C and cR<=K:
        Right.append(N-i-1)
        Rast=i
        cR+=1
Right=Right[::-1]

ans=[]

for k in range(K):
    if Left[k]==Right[k]:
        ans.append(Left[k]+1)
print(ans)
Problem p02730 (python)

Fixed submission:
def c1(S):
    N=len(S)
    if S == S[::-1]:
        return True
    else:
        return False

S=input()
N=len(S)
SS=S[:(N-1)//2]
SSS=S[(N+3)//2-1:]
if SS==SSS and c1(SS):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):

# 回分判定
def palind(LIST, N):
    for i in range(N):
        if LIST[i] != LIST[-1-i]:
            return False
    return True
​
S = list(input())
# front: Sの前半, rear: Sの後半
front = S[:((len(S)-1)//2)]
# Sおよびfrontが回分であれば真 (frontが回分ならば、rearも回分であることは自明)
if palind(S, len(S)) and palind(front, len(front)):
    print('Yes')
else:
    print('No')
Problem p02761 (python)

Fixed submission:
N,M=map(int,input().split())
s=[]
c=[]
for _ in range(M):
    S,C=map(int,input().split())
    s.append(S)
    c.append(C)

num=[10]*N

for i in range(M):
    if N>1 and s[i]==1 and c[i]==0:
        num="-1"
        break
    elif num[s[i]-1]==10:
        num[s[i]-1]=c[i]
    elif num[s[i]-1]!=10 and num[s[i]-1]!=c[i]:
        num="-1"
        break
if num=="-1":
    print(num)
else:
    for l in range(N):
        if num[l]==10:
            num[l]=0
    if num[0]==0 and N>1:
        num[0]=1
    for j in range(N):
        print(num[j],end="")

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
s=[]
c=[]
for _ in range(M):
    S,C=map(int,input().split())
    s.append(S)
    c.append(C)

num=[10]*N

for i in range(M):
    if s[i]==1 and c[i]==0:
        num="-1"
        break
    elif num[s[i]-1]==10:
        num[s[i]-1]=c[i]
    elif num[s[i]-1]!=10 and num[s[i]-1]!=c[i]:
        num="-1"
        break
for l in range(N):
    if num[l]==10:
        num[l]=0
if num=="-1":
    print(num)
else:
    if num[0]==0:
        num[0]=1
    for j in range(N):
        print(num[j],end="")
Problem p02842 (python)

Fixed submission:
import math

N=int(input())
X=math.ceil(N/1.08)
if math.floor(X*1.08)==N:
    print(int(X))
else:
    print(":(")

Buggy submission (verdict: Runtime Error):
N=int(input())

X=math.ceil(N/1.08)
if X*1.08==N:
    print(int(X))
else:
    print(":(")
Problem p02845 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7

dp=[1]
col=[]
for i in range(N):
    if A[i]==0:
        col.append(1)
        dp.append(dp[-1]*(4-len(col)))
    else:
        p=0
        for c in range(len(col)):
            if col[c]==A[i]:
                p+=1
                if p==1:
                    col[c]+=1
        dp.append(dp[-1]*p%mod)

print(dp[-1]%mod)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7

dp=[3]
col=[1]
for i in range(1,N):
    if A[i]==0:
        col.append(1)
        dp.append(dp[-1]*(4-len(col)))
    else:
        p=0
        for c in range(len(col)):
            if col[c]==A[i]:
                if p==0:
                    col[c]+=1
                p+=1
        dp.append(dp[-1]*p%mod)
        if p==0:
            print(A[N])
print(dp[-1]%mod)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7

dp=[3]
col=[1]
for i in range(1,N):
    if A[i]==0:
        col.append(1)
        dp.append(dp[-1]*(4-len(col)))
    else:
        dp.append(dp[-1]*col.count(A[i])%mod)
        col[col.index(A[i])]+=1
print(dp[-1]%mod)
Problem p02882 (python)

Fixed submission:
import math

a,b,x=map(int,input().split())
if x<a*a*b//2:
    q=math.degrees(math.atan(a*b*b/(2*x)))
else:
    q=math.degrees(math.atan(2*(a*a*b-x)/(a**3)))
print('{:.10f}'.format(q))

Buggy submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
if x<a*a*b//2:
    q=math.degrees(math.atan(a*b*b/(2*x)))
else:
    q=math.degrees(math.atan(2*(a*a*b-x)/(a**3)))
print('{:.10f}'.format(q))
Problem p02886 (python)

Fixed submission:
N=int(input())
d=list(map(int,input().split()))
HP=0
for i in range(N):
    for j in range(i+1,N):
        HP+=d[i]*d[j]
print(HP)

Buggy submission (verdict: Runtime Error):
3
3 1 2
Problem p02888 (python)

Fixed submission:
import bisect

N=int(input())
L=sorted(list(map(int, input().split())))
S=0

for i in range(N):
    for j in range(i+1,N):
        S+=bisect.bisect_left(L,L[i]+L[j])-j-1
print(S)

Buggy submission (verdict: Runtime Error):
import numpy as np
N=int(input())
L=np.array(list(map(int, input().split())))
S=0
L.sort()
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[i]+L[j]>L[k]:
                S+=1
            else:
                break
print(S)
Problem p02900 (python)

Fixed submission:
import fractions

def prime(n):
    jdg=True
    for i in range(2,round(n**0.5)+1):
        if n%i==0:
            jdg=False
    return jdg

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

    divisors.sort()
    return divisors

A,B=map(int,input().split())
G=fractions.gcd(A,B)
Gd=md(G)
l=[]
ans=0
for g in Gd:
    if prime(g):
        l.append(g)
        ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import math

def prime(n):
    jdg=True
    for i in range(2,round(n**0.5)+1):
        if n%i==0:
            jdg=False
    return jdg

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

    divisors.sort()
    return divisors

A,B=map(int,input().split())
G=math.gcd(A,B)
Gd=md(G)
l=[]
ans=0
for g in Gd:
    if prime(g):
        l.append(g)
        ans+=1
print(ans)
Problem p02936 (python)

Fixed submission:
from collections import deque

N,Q=map(int,input().split())

tree=[[] for _ in range(N)]

for _ in range(N-1):
    A,B=map(int,input().split())
    tree[A-1].append(B-1)
    tree[B-1].append(A-1)

ans=[0 for _ in range(N)]
for j in range(Q):
    p,x=map(int,input().split())
    ans[p-1]+=x

#BFSで親のカウンターを子に継がせる
dist = [-1]*N
que = deque([0])
dist[0] = 0
while que:
    v = que.popleft()
    d = dist[v]
    for w in tree[v]:
        if dist[w] > -1:
            continue
        que.append(w)
        dist[w]=d+1
        ans[w]+=ans[v]

print(*ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(20000)

def dfs(i,x):
    ans[i]+=x
    if dist[i]==bottom:
        return
    for n in tree[i]:
        if dist[n]>dist[i]:
            dfs(n,x)

from collections import deque

N,Q=map(int,input().split())

tree=[[] for _ in range(N)]

for _ in range(N-1):
    A,B=map(int,input().split())
    tree[A-1].append(B-1)
    tree[B-1].append(A-1)

#BFSで各ノードの深さを調べる
dist = [-1]*N
que = deque([0])
dist[0] = 0
while que:
    v = que.popleft()
    d = dist[v]
    for w in tree[v]:
        if dist[w] > -1:
            continue
        dist[w] = d + 1
        que.append(w)

#カウンターをDFSで制御
ans=[0 for _ in range(N)]
bottom=max(dist)
for j in range(Q):
    p,x=map(int,input().split())
    dfs(p-1,x)

print(*ans)

Buggy submission (verdict: Runtime Error):
def dfs(i,x):
    ans[i]+=x
    if dist[i]==bottom:
        return
    for n in tree[i]:
        if dist[n]>dist[i]:
            dfs(n,x)

from collections import deque

N,Q=map(int,input().split())

tree=[[] for _ in range(N)]

for _ in range(N-1):
    A,B=map(int,input().split())
    tree[A-1].append(B-1)
    tree[B-1].append(A-1)

#BFSで各ノードの深さを調べる
dist = [-1]*N
que = deque([0])
dist[0] = 0
while que:
    v = que.popleft()
    d = dist[v]
    for w in tree[v]:
        if dist[w] > -1:
            continue
        dist[w] = d + 1
        que.append(w)

#カウンターをDFSで制御
ans=[0 for _ in range(N)]
bottom=max(dist)
for j in range(Q):
    p,x=map(int,input().split())
    dfs(p-1,x)

print(*ans)
Problem p03006 (python)

Fixed submission:
N=int(input())
x=[list(map(int,input().split())) for _ in range(N)]

v={}
for i in range(N):
    for j in range(N):
        if i==j:
            continue
        vect=[x[i][0]-x[j][0],x[i][1]-x[j][1]]
        vs=str(vect[0])+","+str(vect[1])
        if vs in v:
            v[vs]+=1
        else:
            v[vs]=1

VM=0
for m in v:
    VM=max(VM,v[m])
print(N-VM)

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
    if a%b==0:
        return b
    return gcd(b,a%b)

N=int(input())
v=[list(map(int,input().split())) for _ in range(N)]
d={}

for i in range(1,N):
    for j in range(i):
        if i!=j:
            x=v[i][0]-v[j][0]
            y=v[i][1]-v[j][1]
            if x<0:
                x*=-1
                y*=-1
            if x!=0 and y!=0:
                g=gcd(x,abs(y))
            elif x==0 and y!=0:
                g=y
            else:
                g=x
            x//=g
            y//=g
            V=str(x)+","+str(y)
            if V in d:
                d[V]+=1
            else:
                d[V]=1
M=0
for D in d:
    M=max(M,d[D])
for D in d:
    if d[D]==M:
        ans=N-d[D]
        break
if ans==0:
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd

N=int(input())
v=[list(map(int,input().split())) for _ in range(N)]
d={}

for i in range(1,N):
    for j in range(i):
        if i!=j:
            x=v[i][0]-v[j][0]
            y=v[i][1]-v[j][1]
            if x<0:
                x*=-1
                y*=-1
            g=gcd(x,abs(y))
            x//=g
            y//=g
            V=str(x)+","+str(y)
            if V in d:
                d[V]+=1
            else:
                d[V]=1
M=0
for D in d:
    M=max(M,d[D])
for D in d:
    if d[D]==M:
        ans=N-d[D]
        break
if ans==0:
    ans+=1
print(ans)
Problem p03044 (python)

Fixed submission:
import sys

def dfs(u,D):
    sys.setrecursionlimit(10**6)
    for v,w in tree[u]:
        if d[v]==-1:
            d[v]=(D+w)%2
            dfs(v,D+w)

N=int(input())
d=[-1 for _ in range(N)]
d[0]=0
tree=[[] for _ in range(N)]

for _ in range(N-1):
    u,v,w=map(int,input().split())
    u-=1
    v-=1
    tree[u].append([v,w])
    tree[v].append([u,w])

dfs(0,0)
for i in d:
    print(i%2)

Buggy submission (verdict: Runtime Error):
def dfs(u,D):
    for v,w in tree[u]:
        if d[v]==-1:
            d[v]=(D+w)%2
            dfs(v,D+w)

N=int(input())
d=[-1 for _ in range(N)]
d[0]=0
tree=[[] for _ in range(N)]

for _ in range(N-1):
    u,v,w=map(int,input().split())
    u-=1
    v-=1
    tree[u].append([v,w])
    tree[v].append([u,w])

dfs(0,0)
for i in d:
    print(i%2)

Buggy submission (verdict: Runtime Error):
def dfs(u,D):
    for v,w in tree[u]:
        if d[v]==-1:
            d[v]=(w+D)%2
            dfs(v,D+w)

N=int(input())
d=[-1 for _ in range(N)]
d[0]=0
tree=[[] for _ in range(N)]

for _ in range(N-1):
    u,v,w=map(int,input().split())
    u-=1
    v-=1
    tree[u].append([v,w])
    tree[v].append([u,w])

dfs(0,0)
for i in d:
    print(i%2)
Problem p03050 (python)

Fixed submission:
N=int(input())
ans=0
if N==1:
    ans=0
else:
    for i in range(1,int(N**0.5)+1):
        if (N-i)%i==0:
            q=(N-i)//i
            if N%q==i:
                ans+=(N-i)//i
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
ans=0
for i in range(1,int(N**0.5)+1):
    if (N-i)%i==0:
        q=(N-i)//i
        if N%q==i:
            ans+=(N-i)//i
print(ans)
Problem p03231 (python)

Fixed submission:
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

N,M=map(int,input().split())
S=input()
T=input()

C=N*M//gcd(max(N,M),min(N,M))
n=C//N
m=C//M

i=0
j=0
ans=C
while i<C and j<C:
    if  i==j:
        if S[i//n]!=T[j//m]:
            ans=-1
        i+=n
        j+=m
    elif i<j:
        i+=n
    else:
        j+=m
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
N,M=map(int,input().split())
S=input()
T=input()

C=N*M//gcd(N,M)
n=C//N
m=C//M

i=0
j=0
ans=C
while i<C and j<C:
    if  i==j:
        if S[i//n]!=T[j//m]:
            ans=-1
        i+=n
        j+=m
    elif i<j:
        i+=n
    else:
        j+=m
print(ans)
Problem p03240 (python)

Fixed submission:
N=int(input())
L=[]
for h in range(N):
    Cx,Cy,h=map(int,input().split())
    L.append([h,Cx,Cy])
L.sort(reverse=True)

for x in range(101):
    for y in range(101):
        cond=True
        H=L[0][0]+abs(x-L[0][1])+abs(y-L[0][2])
        for i in range(1,N):
            h=L[i][0]+abs(x-L[i][1])+abs(y-L[i][2])
            if L[i][0]>0:
                if h!=H:
                    cond=False
                    break
            else:
                if h<H:
                    cond=False
                    break
        if cond:
            break
    if cond:
        break

print(x,y,H)

Buggy submission (verdict: Runtime Error):
N=int(input())
L=[list(map(int,input().split())) for _ in range(N)]

for x in range(101):
    for y in range(101):
        cond=True
        H=abs(x-L[0][0])+abs(y-L[0][1])+L[0][2]
        if H<=0:
            cond=False
            continue
        for i in range(1,N):
            if H!=L[i][2]+abs(x-L[i][0])+abs(y-L[i][1]):
                cond=False
                break
        if cond:
            ans=[x,y,H]

print(ans[0],ans[1],ans[2])
Problem p03325 (python)

Fixed submission:
from functools import reduce
from operator import mul

def two(a,ans):
    if a%2==0:
        return two(a//2,ans+1)
    else:
        return ans

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

#ans1=0
ans2=0
#p=reduce(mul,A)
#ans1=two(p,ans1)
for i in range(N):
    ans2=two(A[i],ans2)
print(ans2)

Buggy submission (verdict: Runtime Error):
from functools import reduce
from operator import mul

def two(a,ans):
    if a%2==0:
        return two(a//2,ans+1)
    else:
        return ans

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

ans1=0
ans2=0
p=reduce(mul,A)
ans1=two(p,ans1)
for i in range(N):
    ans2=two(A[i],ans2)
print(ans2)
Problem p03565 (python)

Fixed submission:
S=input()
T=input()
SL=list(S)
N=len(S)
M=len(T)

if len(S)<len(T):
    print("UNRESTORABLE")
    
else:
    for i in range(N-M+1):
        cond=True
        temp=S[N-M-i:N-i]
        for s in range(M):
            if temp[s]!="?" and temp[s]!=T[s]:
                cond=False
        if cond:
            SL[N-M-i:N-i]=list(T)
            break
    if not cond:
        print("UNRESTORABLE")
    else:
        for j in range(N):
            if SL[j]=="?":
                SL[j]="a"
    
        for a in SL:
            print(a,end="")

Buggy submission (verdict: Runtime Error):
S=input()
T=input()
SL=list(S)
N=len(S)
M=len(T)

for i in range(N-M+1):
    cond=True
    temp=S[N-M-i:N-i]
    for s in range(M):
        if temp[s]!="?" and temp[s]!=T[s]:
            cond=False
    if cond:
        SL[N-M-i:N-i]=list(T)
        break
if not cond:
    print("UNRESTORABLE")
else:
    for j in range(N):
        if SL[j]=="?":
            SL[j]="a"

    for a in SL:
        print(a,end="")
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())
one = 0

for s in S:
  if s=="1":
    one+=1
  else:
    ans = s
    break

if K<=one:
  print(1)
else:
  print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
K = input()

if S[0]=="1":
  print(S[1])
  
else:
  print(S[0])
Problem p03359 (python)

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

if a<=b:
  print(a)
else:
  print(a-1)

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
S = ["."*(W+2)]+["."+input()+"." for h in range(H)]+["."*(W+2)]

for h in range(1,H+1):
  for w in range(1,W+1):
    if S[h][w]=="#" and S[h-1][w]=="." and S[h+1][w]=="." and S[h][w-1]=="." and S[h][w+1]==".":
      print("No")
      exit()
      
print("Yes")
Problem p03544 (python)

Fixed submission:
N = int(input())
L0 = 2
L1 = 1

if N==1:
  print(1)

else:
  for n in range(N-1):
    L = L0+L1
    L0 = L1
    L1 = L
  print(L)

Buggy submission (verdict: Runtime Error):
N = int(input())
L0 = 2
L1 = 1

for n in range(N-1):
  L = L0+L1
  L0 = L1
  L1 = L
  
print(L)
Problem p02665 (python)

Fixed submission:
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n = int(input())
    n += 1
    a = list(map(int, input().split()))
    c = [0] * (n + 1)
    for i in range(n):
        c[i + 1] = c[i] + a[i]
    ans = [0] * n
    for i in range(n):
        ans[i] = c[n] - c[i]
    if n == 1 and a[0] == 0:
        print(-1)
        return
    if n > 1 and a[0] > 0:
        print(-1)
        return
    ans[0] = min(1, ans[0])
    if ans[0] < a[0]:
        print(-1)
        return
    for i in range(1, n):
        ans[i] = min(ans[i], (ans[i-1]-a[i-1]) * 2)
        if ans[i] < a[i]:
            print(-1)
            return

    print(sum(ans))
main()

Buggy submission (verdict: Runtime Error):
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n = int(input())
    n += 1
    a = list(map(int, input().split()))
    c = [0] * (n + 1)
    for i in range(n):
        c[i + 1] = c[i] + a[i]
    ans = [0] * n
    for i in range(n):
        ans[i] = c[n] - c[i]
    if n == 1 and a[0] == 0:
        print(-1)
        return
    if n > 1 and a[o] > 0:
        print(-1)
        return
    ans[0] = min(1, ans[0])
    for i in range(1, n):
        ans[i] = min(ans[i], (ans[i-1]-a[i-1]) * 2)
        if ans[i] < a[i]:
            print(-1)
            return

    print(sum(ans))
main()
Problem p02696 (python)

Fixed submission:
a, b, n = map(int, input().split())
print(a * min((b-1), n) // b)

Buggy submission (verdict: Runtime Error):
a, b, n = map(int, input().split())
print(a * (b-1) // b))
Problem p02697 (python)

Fixed submission:
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n, m = map(int, input().split())
    ans = []
    for i in range(1, (m+1)//2+1):
        ans.append([i, m+2-i])

    for i in range(1, (m+1)//2+1):
        if len(ans) == m:
            break
        ans.append([m+1+i, 2*m+2-i])

    for x in ans:
        print(x[0], x[1])

main()

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[[] for i in range(m)]
for i in range(m):
  a[i].append(i+1)
  
for i in range(m):
  a[-1-i].append(i+1+m)
a[-1]=n
for x in a:
  print(x[0],x[1])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[[] for i in range(m)]
for i in range(m):
  a[i].append(i+1)
  
for i in range(m):
  a[-1-i].append(i+1+m)
 
a[-1]=n
for x in a:
  print(x[0],x[1])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[]*m
for i in range(m):
  a[i].append(i+1)
  
for i in range(m):
  a[-1-i].append(i+1+m)
  
for x in a:
  print(x[0],x[1])
Problem p02823 (python)

Fixed submission:
n,a,b=map(int,input().split())
if abs(a-b)%2 == 0:
  print(abs(a-b)//2)
else:
  print(min((2*n-a-b)//2+1,(a+b-2)//2+1))

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
if abs(a-b)%2 == 0:
  print(abs(a-b)//2)
else:
  print(min(b-1,n-a,n-b+(b-a-n+b)//2+1,a-1+(b-a-a+1)//2+1)

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
if abs(a-b)%2 == 0:
  print(abs(a-b)//2)
else: