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

Fixed submission:
n,*a=map(int,open(0).read().split())
a.sort()
print(sum(abs(i)for i in a)-2*min(abs(a[-1]),abs(a[0]))*(a[0]*a[-1]>0))
if a[0]>0:
    print(a[0],a[-1])
    a[0]-=a[-1]
    for i in a[1:-2]:
        print(a[0],i)
        a[0]-=i
    print(a[-2],a[0])
elif a[-1]<0:
    for i in a[:-1]:
        print(a[-1],i)
        a[-1]-=i
else:
    for i in a[1:-1]:
        if i<0:
            print(a[-1],i)
            a[-1]-=i
        else:
            print(a[0],i)
            a[0]-=i
    print(a[-1],a[0])

Buggy submission (verdict: Runtime Error):
n,*a=map(int,open(0).read().split())
a.sort()
print(sum(abs(i)for i in a)-2*abs(a[0]))
if n==2:
    print(a[1]-1[0])
    print(a[1],a[0])
else:
    print(a[0],a[-1])
    a[0]-=a[-1]
    for i in a[1:-2]:
        print(a[0],i)
        a[0]-=i
    print(a[-2],a[0])

Buggy submission (verdict: Runtime Error):
n,*a=map(int,open(0).read().split())
a.sort()
p,z,m=[],[],[]
for i in a:
    if i<0:m+=[i]
    elif i>0:p+=[i]
    else:z+=[i]
if p and m:
    p=z+p
    for i in p[:-1]:
        # print(m[0],i)
        m[0]-=i
    for i in m:
        # print(p[-1],i)
        p[-1]-=i
    print(p[-1])    
elif p:
    p=z+p
    for i in p[:-2]:
        # print(p[0],i)
        p[0]-=i
    print(p[-2]-p[0])    
elif m:
    m=m+z
    for i in p[:-1]:
        # print(p[-1],i)
        p[-1]-=i
    print(p[-1])    
if p and m:
    p=z+p
    for i in p[:-1]:
        print(m[0],i)
        m[0]-=i
    for i in m:
        print(p[-1],i)
        p[-1]-=i
elif p:
    p=z+p
    for i in p[:-2]:
        print(p[0],i)
        p[0]-=i
    print(p[-2],p[0])    
elif m:
    m=m+z
    for i in p[:-1]:
        print(p[-1],i)
        p[-1]-=i

Buggy submission (verdict: Runtime Error):
if p and m:
    p=z+p
    for i in p[:-1]:
        print(m[0],i)
        m[0]-=i
    for i in m:
        print(p[-1],i)
        p[-1]-=i
elif p:
    p=z+p
    for i in p[:-2]:
        print(p[0],i)
        p[0]-=i
    print(p[-2],p[0])    
elif m:
    m=m+z
    for i in p[:-1]:
        print(p[-1],i)
        p[-1]-=i
Problem p03047 (python)

Fixed submission:
n,k=map(int, input().split())
print(n-k+1)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=[input() for i in range(n)]
ans=sum([s[i].count("AB") for i in range(n)])
a=[s[i].count("AB") for i in range(n)]
xxA=sum([1 if s[i][0]!="B" and s[i][-1]=="A"else 0 for i in range(n)])
Bxx=sum([1 if s[i][0]=="B" and s[i][-1]!="A" else 0 for i in range(n)])
BxA=sum([1 if s[i][0]=="B" and s[i][-1]=="A" else 0 for i in range(n)])
if abs(xxA-Bxx)>BxA:
    wer=min(xxA,Bxx)+BxA+1
else:
    wer=min(xxA,Bxx)+BxA
print(ans+wer)
Problem p03069 (python)

Fixed submission:
ans=n=int(input())
s=input()
a=[0]
for i in s:
    if i==".":
        a+=[a[-1]+1]
    else:
        a+=[a[-1]]
w=s.count(".")
for i in range(n+1):
    ans=min(ans,i-a[i]+w-a[i])
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
print(min(s[s.index("#"):].count("."),s[:-1].count("#")))
Problem p03106 (python)

Fixed submission:
a,b,k=map(int, input().split())
ans=[]
for i in range(max(a,b)):
    if a%(i+1)==0 and b%(i+1)==0:
        ans.append(i+1)
print(ans[-k])

Buggy submission (verdict: Runtime Error):
a,b,k=map(int, input().split())
ans=[]
for i in range(1,max(a,b)):
    if a%i==0 and b%i==0:
        ans.append(i)
print(ans[-k])
Problem p03145 (python)

Fixed submission:
a,b,c=sorted(map(int, input().split()))
print(a*b//2)

Buggy submission (verdict: Runtime Error):
n=int(input())
h=list(map(int, input().split()))
sum=0
for i in range(max(h)):
    if 0 not in h:
        h=[i-1 if i>0 else 0 for i in h]
        sum+=1
        # print(h,1)
    else:
        count0=[i for i, j in enumerate(h) if j==0]
        a=count0.copy() #copy()をつけないとaを変えるとcount0も変わる
        b=count0.copy()
        a.pop(0)
        b.pop(-1)
        c=[x-y for(x,y) in zip(a,b)]#a-bが要素のリストを作る
        sum = sum + len(c)-c.count(1)
        # print(count0)
        if count0[0]>0 and count0[-1]<n-1:
            sum +=2
            # print(1)
        elif count0[0]>0 or count0[-1]<n-1:
            sum +=1
            # print(2)
        else:
            sum +=0
        h=[i-1 if i>0 else 0 for i in h]
        # print(h,2)
print(sum)
Problem p03147 (python)

Fixed submission:
n=int(input())
h=list(map(int, input().split()))
sum=0
for i in range(max(h)):
    if 0 not in h:
        h=[X-1 if X>0 else 0 for X in h]
        sum+=1
        # print(h,1)
    else:
        count0=[Y for Y, Z in enumerate(h) if Z==0]
        a=count0.copy()
        b=count0.copy()
        del a[0]
        del b[-1]
        c=[x-y for(x,y) in zip(a,b)]
        sum = sum + len(c)-c.count(1)
        if count0[0]>0 and count0[-1]<n-1:
            sum +=2
        elif count0[0]>0 or count0[-1]<n-1:
            sum +=1
        else:
            sum +=0
        h=[i-1 if i>0 else 0 for i in h]
print(sum)

Buggy submission (verdict: Runtime Error):
n=int(input())
h=list(map(int, input().split()))
sum=0
for i in range(max(h)):
    if 0 not in h:
        h=[i-1 if i>0 else 0 for i in h]
        sum+=1
    else:
        count0=[i for i, j in enumerate(h) if j==0]
        a=count0.copy() #copy()をつけないとaを変えるとcount0も変わる
        b=count0.copy()
        del a[0]
        del b[-1]
        c=[x-y for(x,y) in zip(a,b)]　#a-bが要素のリストを作る
        sum = sum + len(c)-c.count(1)
        if count0[0]>0 and count0[-1]<n-1:
            sum +=2
        elif count0[0]>0 or count0[-1]<n-1:
            sum +=1
        else:
            sum +=0
        h=[i-1 if i>0 else 0 for i in h]
print(sum)
Problem p03160 (python)

Fixed submission:
n=int(input())
h=[int(i) for i in input().split()]
dp=[0]*n
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
dp=[10**9]*n
dp[0]=0
dp[1]=abs(a[1]-a[0])
for i in range(2,n):
    for j in range(max(0,i-k),i):
        dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i])
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n=int(input())
h=[int(i) for i in input().split()]
memo=[-1]*(n+1)
def flog(n):
    if n<=0:
        memo[n]=0
        return 0
    if memo[n]!=-1:
        return memo[n]
    else:
        memo[n]=min(flog(n-1)+abs(h[n]-h[n-1]),flog(n-2)+abs(h[n]-h[n-2]))
        return memo[n]
print(flog(n-1))

Buggy submission (verdict: Runtime Error):
n=int(input())
h=[int(i) for i in input().split()]
memo=[-1]*(n+1)
def flog(n):
    if n<=0:
        memo[0]=0
        return 0
    if n==1:
        memo[1]=abs(h[0]-h[1])
        return memo[n]
    if memo[n]!=-1:
        return memo[n]
    else:
        memo[n]=min(flog(n-1)+abs(h[n]-h[n-1]),flog(n-2)+abs(h[n]-h[n-2]))
        return memo[n]
print(flog(n-1))
Problem p03161 (python)

Fixed submission:
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
dp=[10**9]*n
dp[0]=0
dp[1]=abs(a[1]-a[0])
for i in range(2,n):
    for j in range(max(0,i-k),i):
        dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i])
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=[int(i) for i in input().split()]
inf=pow(10,6)
dp=[inf]*(n)
dp[0]=0
dp[1]=abs(h[0]-h[1])
for i in range(n):
    for j in range(min(k+1):
        if i+j<n:
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
dp=[np.inf]*n
dp[0]=0
dp[1]=abs(a[1]-a[0])

for i in range(2,n):
    for j in range(max(0,i-k),i):
        dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i])
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
dp=[np.inf]*n
dp[0]=0
dp[1]=abs(a[1]-a[0])
for i in range(2,n):
  for j in range(max(0,i-k),i):
    dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i])
print(dp[-1])

Buggy submission (verdict: Runtime Error):
def main():
  import numpy as np
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
dp=[np.inf]*n
dp[0]=0
dp[1]=abs(a[1]-a[0])
for i in range(2,n):
    for j in range(1,k+1):
        dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i])
print(dp[-1])
if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
import numpy as np
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
dp=[np.inf]*n
dp[0]=0
dp[1]=abs(a[1]-a[0])
for i in range(2,n):
    for j in range(1,k+1):
        dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i])
print(dp[-1])
Problem p03164 (python)

Fixed submission:
import numpy as np
N,W=map(int,input().split())
dp=np.full(10**5+1,W+1)
dp[0]=0
for i in range(N):
    w,v=map(int,input().split())
    dp[v:]=np.minimum(dp[:-v]+w,dp[v:])
print(np.max(np.where(dp<=W)))

Buggy submission (verdict: Runtime Error):
from numpy import*
f=lambda:map(int,input().split())
N,W=f()
T=zeros(W+1,int)
exec('w,v=f();T[w:]=maximum(T[w:],T[:-w]+v);'*N)
print(T[-1])

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

Fixed submission:
from math import *
a,b=map(int,input().split())
s=input()
t=input()
g=gcd(a,b)
for i in range(g):
    if s[a//g*i]!=t[b//g*i]:
        print(-1)
        exit()
print(a*b//g)

Buggy submission (verdict: Runtime Error):
from math import *
a,b=map(int,input().split())
s=input()
t=input()
ans=a*b//gcd(a,b)
if a%b==0:
    if not all(s[i]==t[1+i*a//b] for i in range(b)):ans=-1
if b%a==0:
    if not all(t[i]==s[1+i*b//a] for i in range(a)):ans=-1
if s[0]!=t[0]:
    ans=-1
print(ans)

Buggy submission (verdict: Runtime Error):
from math import *
a,b=map(int,input().split())
s=input()
t=input()
ans=a*b//gcd(a,b)
if a%b==0:
    if not all(s[i]==t[1+i*a//b] for i in range(b)):ans=-1
if b%a==0:
    if not all(t[i]==s[1+i*b//a] for i in range(a)):ans=-1
print(ans)
Problem p03262 (python)

Fixed submission:
import fractions
n,*x=map(int,open(0).read().split())
x.sort()
a=[i-j for i,j in zip(x[1:],x[:-1])]
set(a)
a.sort()
b=[i for i in a if i%a[0]]
b.append(a[0])
if len(b)==1:
    print(*b)
else:
    ans=b[0]
    for i in b[1:]:
        ans=fractions.gcd(ans,i)
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
n,*x=map(int,open(0).read().split())
x.sort()
a=[i-j for i,j in zip(x[1:],x[:-1])]
set(a)
a.sort()
b=[i for i in a if i%a[0]]
b.append(a[0])
if len(b)==1:
    print(*b)
else:
    ans=b[0]
    for i in b[1:]:
        ans=math.gcd(ans,i)
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
n,s,*x=map(int,open(0).read().split())
a=[abs(i-s) for i in x]
set(a)
ans=min(a)
for i in a:
    if i%ans==0:
        continue
    else:
        ans=math.gcd(ans,ans%i)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n,s,*x=map(int,open(0).read().split())
a=[abs(i-s) for i in x]
set(a)
ans=a[0]
for i in a[1:]:
    if i%ans==0:
        continue
    else:
        ans=math.gcd(ans,i)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n,*x=map(int,open(0).read().split())
x.sort()
a=[i-j for i,j in zip(x[1:],x[:-1])]
set(a)
a.sort()
b=[i for i in a if i%a[0]]
b.append(a[0])
if len(b)==1:
    print(*b)
else:
    print(gcd(b[0],b[1]))

Buggy submission (verdict: Runtime Error):
import math
n,*x=map(int,open(0).read().split())
x.sort()
a=[i-j for i,j in zip(x[1:],x[:-1])]
set(a)
a.sort()
b=[i for i in a if i%a[0]]
b.append(a[0])
if len(b)==1:
    print(*b)
else:
    ans=b[0]
    for i,j in zip(b[1:],b[:-1]):
        ans=min(ans,gcd(i,j))
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
import itertools
n,*x=map(int,open(0).read().split())
x.sort()
a=[i-j for i,j in zip(x[1:],x[:-1])]
set(a)
a.sort()
b=[i for i in a if i%a[0]]
b.append(a[0])
if len(b)==1:
    print(*b)
else:
    ans=b[0]
    for i,j in itertools.combinations(b, 2):
        ans=min(ans,gcd(i,j))
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
n,*x=map(int,open(0).read().split())
x.sort()
a=[i-j for i,j in zip(x[1:],x[:-1])]
set(a)
ans=a[0]
b=a[0]
for i in a[1:]:
    ans=min(ans,math.gcd(i,b))
    b=i
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n,*x=map(int,open(0).read().split())
x.sort()
a=[i-j for i,j in zip(x[1:],x[:-1])]
set(a)
ans=b=a[0]
for i in a[1:]:
    ans=min(ans,math.gcd(i,b))
    b=i
print(ans)
Problem p03274 (python)

Fixed submission:
n,k,*a=map(int,open(0).read().split())
ans=10**9
for i in range(n-k+1):
    b,c=a[i],a[i+k-1]
    ans=min(ans,min(abs(b),abs(c))+abs(b-c))
print(ans)

Buggy submission (verdict: Runtime Error):
n,k,*a=map(int,open(0).read().split())
b,c=[],[0]
for i in a:
    if i<0:
        b+=[-i]
    elif i==0:
        k-=1
    else:
        c+=[i]
b=[0]+b[::-1]        
ans=10**9
B,C=len(b),len(c)
for i in range([0,abs(C-k-1)][C-k-1<0],B):
    ans=min(ans,b[i]+c[k-i]+min(b[i],c[k-i]))
print(ans)
Problem p03438 (python)

Fixed submission:
n,*a=map(int,open(0).read().split())
u=d=z=r=0
for i,j in zip(a[:n],a[n:]):
    if j-i>0:u+=(j-i)//2*2;r+=(j-i)%2
    elif j-i==0:z+=1
    else:d+=j-i
print("Yes" if u+2*d>=0 else "No")

Buggy submission (verdict: Runtime Error):
n,*a=map(int,open(0).read().split())
u=d=z=r=0
for i,j in zip(a[:n],a[n:]):
    if j-i>0:u+=(j-i)//2*2;r+=(j-i)%2
    elif j-i==0:z+=1
    else:d+=[j-i]
print("Yes" if u+2*d>=0 else "No")
Problem p03475 (python)

Fixed submission:
n=int(input())
a=[list(map(int,input().split())) for _ in range(n-1)]
ans=[]
for i in range(n):
    now=0
    for j in range(i,n-1):
        c,s,f=a[j]
        if s==now:
            k=0
        elif s>now:
            k=s-now
        else:
            if now%f!=0:
                k=f-now%f
            else:
                k=0
        now+=c+k
    print(now)

Buggy submission (verdict: Runtime Error):
(n,),*a=[[*map(int,i.split())]for i in open(0)]
ans=[]
for i in range(n-1):
    now=a[i][0]+a[i][1]
    for j in range(i+1,n-1):
        c,s,f=a[j]
        if s==now:
            d=0
        elif s>now:
            d=s-now
        else:
            d=now%f
        now+=c+d
    ans+=[now]  
ans+=[0]    
print(*ans,sep="\n")
Problem p03523 (python)

Fixed submission:
a=["KIH","B","R",""]
ans=[]
aaa=[]
for i in range(16):
    b=""
    for j,k in enumerate(a):
        if ((i >> j) & 1):
            b+="A"
        b+=k
    ans.append(b)
print("YES" if input() in ans else "NO")

Buggy submission (verdict: Runtime Error):
s=input()
j=0
for i in "AKIHABARA":
    if i==s[j]:
        j+=1
    elif i=="A":
        continue
    elif j==len(s):
        break
    else:
        print("NO")
        exit()
print("YES")

Buggy submission (verdict: Runtime Error):
s=input()
j=0
for i in "AKIHABARA":
    if i==s[j] or i=="A":
        j+=1
    else:
        print("NO")
        exit()
print("YES")

Buggy submission (verdict: Runtime Error):
s=input()
a="AKIHABARA"
j=0
for i in s:
    if i==a[j]:
        j+=1
    elif j<8:
        if i==a[j+1] and a[j]=="A":
            j+=2
    else:
        print("NO")
        exit()
print("YES")

Buggy submission (verdict: Runtime Error):
s=input()
a="AKIHABARA"
j=0
for i in s:
    if i==a[j]:
        j+=1
    elif i==a[j+1] and a[j]=="A" and j<8:
        j+=2
    else:
        print("NO")
        exit()
print("YES")

Buggy submission (verdict: Runtime Error):
s=input()
a="AKIHABARA"
j=0
for i in s:
    if j>8:
        print("NO")
        exit()
    if i==a[j]:
        j+=1
    elif i==a[j+1] and a[j]=="A":
        j+=2
    else:
        print("NO")
        exit()
print("YES")
Problem p03607 (python)

Fixed submission:
import sys
input=sys.stdin.readline
n=int(input())
a=[int(input()) for _ in range(n)]
a.sort()
h=a[0]
ans=1
for i in a[1:]:
    if i!=h:
        ans+=1
        h=i
    else:
        ans-=1
        h=pow(10,10)    
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=set()
for i in range(n):
    b=int(input())
    if b in a:
        a.remove(b)
    else:
        a.append(b)
print(len(a))
Problem p03665 (python)

Fixed submission:
n,p,*a=map(int,open(0).read().split())
if len([i for i in a if i%2])==0:
    print(2**n*(p^1))
else:
    print(2**(n-1))

Buggy submission (verdict: Runtime Error):
from math import factorial as f
n,p,*a=map(int,open(0).read().split())
x=len([i for i in a if i%2])
y=n-x

xx=0
for i in range(p,x,2):
    xx+=f(x)//f(i)//f(x-i)

yy=0
for i in range(0,y):
    yy+=f(y)//f(i)//f(y-i)

if x>0 and y>0:
    print(xx*yy+xx*(p^0)+yy*(p^1))
elif x==0:
    print(yy(p^1))
else:
    print(xx)
Problem p03998 (python)

Fixed submission:
from collections import deque
A=deque(input())
B=deque(input())
C=deque(input())
t="a"
for i in range(300):
    if t=="a":
        if len(A)==0:
            print("A")
            exit()
        t=A.popleft()   
    if t=="b":
        if len(B)==0:
            print("B")
            exit()
        t=B.popleft()   
    if t=="c":
        if len(C)==0:
            print("C")
            exit()
        t=C.popleft()

Buggy submission (verdict: Runtime Error):
from collections import deque
A=deque(input())
B=deque(input())
C=deque(input())
t="a"
for i in range(len(A+B+C)):
    if t=="a":
        if len(A)==0:
            print("A")
            exit()
        t=A.popleft()   
    if t=="b":
        if len(B)==0:
            print("B")
            exit()
        t=B.popleft()   
    if t=="c":
        if len(C)==0:
            print("C")
            exit()
        t=C.popleft()
Problem p04029 (python)

Fixed submission:
n = int(input())
c = 0
for i in range(1,n+1):
  c += i
print(c)

Buggy submission (verdict: Runtime Error):
n = input()
c = 0
for i in range(1,n):
  c += i
print(c)

Buggy submission (verdict: Runtime Error):
n = input()
c = 0
for i in range 1 to n:
    c += i
print(c)
Problem p04043 (python)

Fixed submission:

s = input().split()
if s.count("5") == 2 and s.count("7") == 1:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
s = input().split()
if s.count(“5”) == 2 and s.count(“7”) == 1 :
    print(“YES”)
else :
    print(“NO”)
Problem p02609 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

n=II()
s=SI()
p=s.count("1")
p0=p-1
p1=p+1
pw0=[]
pw1=[]
two0=two1=1
for _ in range(n):
    pw0.append(two0)
    pw1.append(two1)
    if p0>0:two0=two0*2%p0
    two1=two1*2%p1

t0=0
t1=0
for i,c in enumerate(s[::-1]):
    if c=="1":
        if p0>0:t0=(t0+pw0[i])%p0
        t1=(t1+pw1[i])%p1

def popcnt(x):
    return bin(x).count("1")

dp0=[-1]*n
def f0(x):
    if x==0:return 1
    if dp0[x]==-1:dp0[x]=f0(x%popcnt(x))+1
    return dp0[x]

ans=[]
for i,c in enumerate(s[::-1]):
    if p0==0 and c=="1":
        ans.append(0)
        continue
    if c=="1":
        cur=(t0-pw0[i])%p0
    else:
        cur=(t1+pw1[i])%p1
    ans.append(f0(cur))

for a in ans[::-1]:print(a)

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

n=II()
s=SI()
p=s.count("1")
p0=p-1
p1=p+1
pw0=[]
pw1=[]
two0=two1=1
for _ in range(n):
    pw0.append(two0)
    pw1.append(two1)
    two0=two0*2%p0
    two1=two1*2%p1

t0=0
t1=0
for i,c in enumerate(s[::-1]):
    if c=="1":
        t0=(t0+pw0[i])%p0
        t1=(t1+pw1[i])%p1

def popcnt(x):
    return bin(x).count("1")

dp0=[-1]*n
def f0(x):
    if x==0:return 0
    if dp0[x]==-1:dp0[x]=f0(x%popcnt(x))+1
    return dp0[x]

ans=[]
for i,c in enumerate(s[::-1]):
    if c=="1":
        cur=(t0-pw0[i])%p0
    else:
        cur=(t1+pw1[i])%p1
    ans.append(f0(cur)+1)

for a in ans[::-1]:print(a)
Problem p02724 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    x=II()
    a,x=divmod(x,500)
    b=x//5
    print(a*1000+b*5)

main()

Buggy submission (verdict: Runtime Error):
from itertools import permutations
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *
from math import gcd

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    x=II()
    c,x=divmod(x,500)
    ans=c*1000+x//5*5
    print(ans)

main()
Problem p02746 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def solve(ai,aj,bi,bj):
    s=pow(3,30)
    dist=abs(ai-bi)+abs(aj-bj)
    while s>1:
        s//=3
        si,sj,ti,tj=ai//s,aj//s,bi//s,bj//s
        if si!=ti:
            return dist
        if abs(sj-tj)>1 and si%3==1:
            up=s*si-1
            down=s*(si+1)
            return min(min(ai,bi)-up,down-max(ai,bi))*2+dist
    return dist

def main():
    q=II()
    for _ in range(q):
        ai,aj,bi,bj=MI1()
        if abs(ai-bi)>abs(aj-bj):ai,aj,bi,bj=aj,ai,bj,bi
        print(solve(ai,aj,bi,bj))

main()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def solve(ai,aj,bi,bj):
    s=pow(3,30)
    dist=abs(ai-bi)+abs(aj-bj)
    while 1:
        s//=3
        si,sj,ti,tj=ai//s,aj//s,bi//s,bj//s
        if si==sj and ti==tj:continue
        if si!=ti:return dist
        if abs(sj-tj)>1 and si%3==1:
            up=s*(si-1)-1
            down=s*si
            return min(min(ai,bi)-up,down-max(ai,bi))*2+dist

def main():
    q=II()
    for _ in range(q):
        ai,aj,bi,bj=MI1()
        if abs(ai-bi)<abs(aj-bj):ai,aj,bi,bj=bi,bj,ai,aj
        print(solve(ai,aj,bi,bj))

main()