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

Fixed submission:
h,w = (int(i) for i in input().split())
a=[ ]
for i in range(h):
  a.append(input())
print('#'*(w+2))
for i in range(h):
  print('#'+ a[i] + '#')
print('#'*(w+2))

Buggy submission (verdict: Runtime Error):
h,w = (int(i) for i in input().split())
a[]
for i in range(h):
  a.append(input())
print('#'*(w+2))
for i in range(h):
  print('#'+ a[i] + '#')
print('#'*(w+2))
Problem p03853 (python)

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

for i in range(h):
  s=input()
  print(s)
  print(s)

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

for i in range(h):
  s=input()
  print(s)
  print(s)
Problem p03998 (python)

Fixed submission:
a = list(input())
b = list(input())
c = list(input())
key = "a"
for i in range(300):
  if key == "a":
    if len(a) == 0:
      print("A")
      break
    else:
      key = a[0]
      a = a[1:]
      
  elif key == "b":
    if len(b) == 0:
      print("B")
      break
    else:
      key = b[0]
      b = b[1:]
      
  else:
    if len(c) == 0:
      print("C")
      break
    else:
      key = c[0]
      c = c[1:]

Buggy submission (verdict: Runtime Error):
a = list(input())
b = list(input())
c = list(input())
key = "a"
for i in range(300):
  if key = "a":
    if len(a) == 0:
      print("A")
      break
    else:
      key = a[0]
      a = a[1:]
      
  elif key = "b":
    if len(b) == 0:
      print("B")
      break
    else:
      key = b[0]
      b = b[1:]
      
  else:
    if len(c) == 0:
      print("C")
      break
    else:
      key = c[0]
      c = c[1:]
Problem p02609 (python)

Fixed submission:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
X=input()
def popcount(x):
  x=x-((x>>1)&0x5555555555555555)
  x=(x&0x3333333333333333)+((x>>2)&0x3333333333333333)

  x=(x+(x>>4))&0x0f0f0f0f0f0f0f0f
  x=x+(x>>8)
  x=x+(x>>16)
  x=x+(x>>32)
  return x&0x0000007f

F=[0]*(n+1)
F[1]=1
for i in range(2,n+1):
  F[i]=1+F[i%popcount(i)]

ct=X.count("1")
if ct==0:
  for _ in range(n):
    print(1)
elif ct==1:
  for i in range(n):
    if X[i]=="1":
      cur=i
      break
  for i in range(n):
    if i==cur:
      print(0)
    else:
      if i==n-1 or cur==n-1:
        print(2)
      else:
        print(1)

else:
  a,b=0,0
  for i in range(n):
    if X[n-1-i]=="1":
      a=(a+pow(2,i,ct-1))%(ct-1)
      b=(b+pow(2,i,ct+1))%(ct+1)
  for i in range(n):
    if X[i]=="0":
      print(F[(b+pow(2,n-1-i,ct+1))%(ct+1)]+1)
    else:
      print(F[(a-pow(2,n-1-i,ct-1))%(ct-1)]+1)

Buggy submission (verdict: Runtime Error):
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
X=input()
def popcount(x):
  x=x-((x>>1)&0x5555555555555555)
  x=(x&0x3333333333333333)+((x>>2)&0x3333333333333333)

  x=(x+(x>>4))&0x0f0f0f0f0f0f0f0f
  x=x+(x>>8)
  x=x+(x>>16)
  x=x+(x>>32)
  return x&0x0000007f

F=[0]*(n+1)
F[1]=1
F[2]=1
for i in range(3,n+1):
  F[i]=1+F[i%popcount(i)]

ct=X.count("1")
if ct==0:
  for _ in range(n):
    print(1)
else:
  a,b=0,0
  for i in range(n):
    if X[n-1-i]=="1":
      a=(a+pow(2,i,ct-1))%(ct-1)
      b=(b+pow(2,i,ct+1))%(ct+1)
  for i in range(n):
    if X[i]=="0":
      print(F[(b+pow(2,n-1-i,ct+1))%(ct+1)]+1)
    else:
      print(F[(a-pow(2,n-1-i,ct-1))%(ct-1)]+1)
Problem p02703 (python)

Fixed submission:
import sys
input=lambda: sys.stdin.readline().rstrip()
import heapq
n,m,s=map(int,input().split())
s=min(s,2499)
E=[]
for _ in range(m):
  E.append(tuple(map(int,input().split())))
CD=[]
for _ in range(n):
  CD.append(tuple(map(int,input().split())))
nn=n*2500
edge=[[] for i in range(nn)]
for u,v,a,b in E:
  u-=1
  v-=1
  for i in range(a,2500):
    edge[u*2500+i].append(b*10**6+v*2500+i-a)
    edge[v*2500+i].append(b*10**6+u*2500+i-a)
for i in range(n):
  c,d=CD[i]
  for j in range(2500):
    if j+c<2500:
      edge[i*2500+j].append(d*10**6+i*2500+j+c)

def dijkstra_heap(s):
  d=[float("inf")]*nn
  used=[True]*nn
  d[s]=0
  used[s]=False
  edgelist=[]
  for e in edge[s]:
    heapq.heappush(edgelist,e)
  while edgelist:
    minedge=heapq.heappop(edgelist)
    minedge_cost=minedge//(10**6)
    minedge_v=minedge%(10**6)
    if not used[minedge_v]:
      continue
    d[minedge_v] = minedge_cost
    used[minedge_v] = False
    for e in edge[minedge_v]:
      e_cost=e//(10**6)
      e_v=e%(10**6)
      if used[e_v]:
        heapq.heappush(edgelist,e+minedge_cost*10**6)
  return d
D=dijkstra_heap(s)
for i in range(1,n):
  ans=D[i*2500]
  for j in range(1,2500):
    ans=min(ans,D[i*2500+j])
  print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=lambda: sys.stdin.readline().rstrip()
import heapq
n,m,s=map(int,input().split())
E=[]
for _ in range(m):
  E.append(tuple(map(int,input().split())))
CD=[]
for _ in range(n):
  CD.append(tuple(map(int,input().split())))
nn=n*2500
edge=[[] for i in range(nn)]
for u,v,a,b in E:
  u-=1
  v-=1
  for i in range(a,2500):
    edge[u*2500+i].append(b*10**6+v*2500+i-a)
    edge[v*2500+i].append(b*10**6+u*2500+i-a)
for i in range(n):
  c,d=CD[i]
  for j in range(2500):
    if j+c<2500:
      edge[i*2500+j].append(d*10**6+i*2500+j+c)

def dijkstra_heap(s):
  d=[float("inf")]*nn
  used=[True]*nn
  d[s]=0
  used[s]=False
  edgelist=[]
  for e in edge[s]:
    heapq.heappush(edgelist,e)
  while edgelist:
    minedge=heapq.heappop(edgelist)
    minedge_cost=minedge//(10**6)
    minedge_v=minedge%(10**6)
    if not used[minedge_v]:
      continue
    d[minedge_v] = minedge_cost
    used[minedge_v] = False
    for e in edge[minedge_v]:
      e_cost=e//(10**6)
      e_v=e%(10**6)
      if used[e_v]:
        heapq.heappush(edgelist,e+minedge_cost*10**6)
  return d
D=dijkstra_heap(s)
for i in range(1,n):
  ans=D[i*2500]
  for j in range(1,2500):
    ans=min(ans,D[i*2500+j])
  print(ans)
Problem p02734 (python)

Fixed submission:
import sys
input=lambda: sys.stdin.readline().rstrip()
n,s=map(int,input().split())
A=[int(i) for i in input().split()]
mod=998244353
B=[[0]*(s+1) for _ in range(n+1)]
ans=0
for i in range(n):
  a=A[i]
  if a<s:
    B[i+1][a]+=i+1
  elif a==s:
    B[i+1][a]+=(i+1)*(n-i)
  for j in range(s+1):
    if j<=s:
      B[i+1][j]+=B[i][j]
    if 0<=j-a and j<s:
      B[i+1][j]+=B[i][j-a]
    if 0<=j-a and j==s:
      B[i+1][j]+=B[i][j-a]*(n-i)
    B[i+1][j]%=mod
print(B[n][s])

Buggy submission (verdict: Runtime Error):
import sys
input=lambda: sys.stdin.readline().rstrip()
n,s=map(int,input().split())
A=[int(i) for i in input().split()]
mod=998244353
B=[[0]*(s+1) for _ in range(n+1)]
ans=0
for i in range(n):
  a=A[i]
  if a<=s:
    B[i+1][a]+=i+1
  for j in range(s+1):
    B[i+1][j]+=B[i][j]
    if 0<=j-a and j<s:
      B[i+1][j]+=B[i][j-a]
    if j==s:
      B[i+1][j]+=B[i][j-a]*(n-i)
    B[i+1][j]%=mod
print(B[n][s])

Buggy submission (verdict: Runtime Error):
import sys
input=lambda: sys.stdin.readline().rstrip()
n,s=map(int,input().split())
A=[int(i) for i in input().split()]
mod=998244353
B=[[[] for i in range(s+1)] for _ in range(n+1)]
B[0][0].append(0)
ans=0
for i in range(n):
  a=A[i]
  B[i+1][a]+=[i+1]
  for j in range(s+1):
    B[i+1][j]+=B[i][j]
    if j-a>=0 and B[i][j-a]:
      B[i+1][j]+=B[i][j-a]
    
  for aa in B[i+1][s]:
    ans+=aa
  ans%=mod
print(ans)
Problem p02742 (python)

Fixed submission:
import sys
input=lambda: sys.stdin.readline().rstrip()
h,w=map(int,input().split())
ans=((h+1)//2+h//2)*(w//2)
if w%2==1:
  ans+=(h+1)//2
if h==1 or w==1:
  ans=1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=lambda: sys.stdin.readline().rstrip()
h,w=map(int,input().split())
ans=((h+1)//2+h//2)*(w//2)
if w%2==1:
  ans+=(h+1)//2
if h==1 or w==1:
  ans=1
peint(ans)
Problem p02749 (python)

Fixed submission:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())

edge = [[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

inf=float("inf")

prv=[inf]*n
prv[0]=-1
depth=[inf]*n
depth[0]=0
stack=[0]
while stack:
  cur=stack.pop()
  for next in edge[cur]:
    if prv[next]==inf:
      prv[next]=cur
      depth[next]=depth[cur]+1
      stack.append(next)
e,o=0,0
for i in range(n):
  if depth[i]%2:
    o+=1
  else:
    e+=1
Ans=[0]*n
if e<=n//3:
  ct1,ct2,ct3=0,0,0
  for i in range(n):
    if not depth[i]%2:
      Ans[i]=3*ct3+3
      ct3+=1
    else:
      if 3*ct2+2<=n:
        Ans[i]=3*ct2+2
        ct2+=1
      elif 3*ct1+1<=n:
        Ans[i]=3*ct1+1
        ct1+=1
      else:
        Ans[i]=3*ct3+3
        ct3+=1
elif o<=n//3:
  ct1,ct2,ct3=0,0,0
  for i in range(n):
    if depth[i]%2:
      Ans[i]=3*ct3+3
      ct3+=1
    else:
      if 3*ct1+1<=n:
        Ans[i]=3*ct1+1
        ct1+=1
      elif 3*ct2+2<=n:
        Ans[i]=3*ct2+2
        ct2+=1
      else:
        Ans[i]=3*ct3+3
        ct3+=1
else:
  ct1,ct2,ct3=0,0,0
  for i in range(n):
    if not depth[i]%2:
      if 3*ct1+1<=n:
        Ans[i]=3*ct1+1
        ct1+=1
      else:
        Ans[i]=3*ct3+3
        ct3+=1
    else:
      if 3*ct2+2<=n:
        Ans[i]=3*ct2+2
        ct2+=1
      else:
        Ans[i]=3*ct3+3
        ct3+=1

print(*Ans)

Buggy submission (verdict: Runtime Error):
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())

edge = [[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

inf=float("inf")

prv=[inf]*n
prv[0]=-1
depth=[inf]*n
depth[0]=0
stack=[0]
while stack:
  cur=stack.pop()
  for next in edge[cur]:
    if prv[next]==inf:
      prv[next]=cur
      depth[next]=depth[cur]+1
      stack.append(next)
Ans=[0]*n
Ans[0]=1
ct1,ct2,ct3=1,0,0
for i in range(1,n):
  if depth(i)%2==0:
    if 3*ct1+1<=n:
      Ans[i]=3*ct1+1
      ct1+=1
    else:
      Ans[i]=3*ct3+3
      ct3+=1
  else:
    if 3*ct2+2<=n:
      Ans[i]=3*ct2+2
      ct2+=1
    else:
      Ans[i]=3*ct3+3
      ct3+=1
if max(Ans)>n:
  print(-1)
else:
  print(*Ans)
Problem p02780 (python)

Fixed submission:
n,k=map(int,input().split())
P=[int(i) for i in input().split()]
ans=0
for i in range(k):
  ans+=(P[i]+1)/2
cur=ans
for i in range(k,n):
  cur+=(P[i]+1)/2
  cur-=(P[i-k]+1)/2
  if cur>ans:
    ans=cur
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
A=[int(i) for i in input().split()]
if len(set(A))==n:
    print("YES")
else:
    print("NO")
Problem p02807 (python)

Fixed submission:
import sys
n=int(input())
X=[int(i) for i in input().split()]
mod=10**9+7
n_max=n
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
  FI[i+1]=pow(F[i+1],mod-2,mod)


ans=0
DP=[0]*n
DP[0]=1
DP[1]=1
ans=(ans+DP[1]*(X[1]-X[0])*F[n-1]*FI[0])%mod
for i in range(2,n):
  DP[i]=(F[i-1]+DP[i-1]*i)%mod
  ans=(ans+DP[i]*(X[i]-X[i-1])*F[n-1]*FI[i])%mod
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
X=[int(i) for i in input().split()]
mod=10**9+7
n_max=n
F=[0]*(n_max+1)
F[0]=1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod

ans=0
DP=[[0]*n for _ in range(n)]
for i in range(1,n):
  for j in range(1,i+1):
    if j==1:
      DP[i][j]=F[i-1]
    elif j==i:
      DP[i][j]=1
    else:
      DP[i][j]=DP[i-1][j-1]+(i-1)*DP[i-1][j]
    ans=(ans+j*DP[i][j]*(X[i]-X[i-1])*F[n-1]//F[i])%mod
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
X=[int(i) for i in input().split()]
mod=10**9+7
n_max=2*10**5
F=[0]*(n_max+1)
F[0]=1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod

ans=0
DP=[[0]*n for _ in range(n)]
for i in range(1,n):
  for j in range(1,i+1):
    if j==1:
      DP[i][j]=F[i-1]
    elif j==i:
      DP[i][j]=1
    else:
      DP[i][j]=DP[i-1][j-1]+(i-1)*DP[i-1][j]
  for j in range(1,i+1):
    ans=(ans+j*DP[i][j]*(X[i]-X[i-1])*F[n-i])%mod
print(ans)
Problem p02814 (python)

Fixed submission:
n,m=map(int,input().split())
A=[int(i)//2 for i in input().split()]

def gcd(a,b):
  while b:
    a,b=b,a%b
  return a

def div2(x):
  ret=0
  while x%2==0:
    ret+=1
    x//=2
  return ret

s=div2(A[0])
chk=True

mul=A[0]
for i in range(1,n):
  if s!=div2(A[i]) or mul>m:
    chk=False
  else:
    mul=mul*A[i]//gcd(mul,A[i])
if not chk:
  print(0)
else:
  print(m//mul-m//(mul*2))

Buggy submission (verdict: Runtime Error):
import sys
input=lambda: sys.stdin.readline().rstrip()

n,m=map(int,input().split())
A=[int(i)//2 for i in input().split()]
ct=0
s=A[0]
while s:
  if s%2==0:
    s//=2
    ct+=1
  else:
    s=0
chk=True
for i in range(1,n):
  cur=0
  a=A[i]
  while a:
  if a%2==0:
    a//=2
    cur+=1
  else:
    a=0
  if cur!=ct:
    chk=False
    break


def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
if not chk:
  print(0)
else:
  lcm=A[0]
  for i in range(1,n):
    lcm*=A[i]//gcd(lcm,A[i])
  print((m//lcm+1)//2)
Problem p02889 (python)

Fixed submission:

from scipy.sparse.csgraph import floyd_warshall
n,m,l=map(int,input().split())
table=[[0]*n for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    table[a-1][b-1]=c
    table[b-1][a-1]=c
d=floyd_warshall(csgraph=table, directed=False, return_predecessors=False)

table2=[[0]*n for i in range(n)]
for i in range(n):
  for j in range(i+1,n):
    if d[i][j]<=l:
      table2[i][j]=1
      table2[j][i]=1
d2=floyd_warshall(csgraph=table2, directed=False, return_predecessors=False)
q=int(input())
for _ in range(q):
  s,t=map(int,input().split())
  if d2[s-1][t-1]==float("inf"):
    print(-1)
  else:
    print(int(d2[s-1][t-1])-1)

Buggy submission (verdict: Runtime Error):
import heapq
n,m,l=map(int,input().split())
edge=[[] for i in range(n)]
for i in range(m):
  a,b,c=map(int,input().split())
  edge[a-1].append([c,b-1])
  edge[b-1].append([c,a-1])

def f(s):
  d=[float("inf")]*n
  used=[True]*n
  d[s]=0
  used[s]=False
  edgelist=[]
  ans=0
  cur=l
  for c,e in edge[s]:
    heapq.heappush(edgelist,c*10**3+e)
  while edgelist:
    minedge=heapq.heappop(edgelist)
    v=minedge[0]%(10**3)
    ans,cur=minedge[0]//(10**13),(minedge[0]%(10**13))//(10**3)
    used[v]=False
    d[v]=ans
    
    for e in edge[v]:
      if used[e[1]]:
        if e[0]>l:
          continue
        elif e[0]+cur>l:
          heapq.heappush(edgelist,(ans+1)*10**13+e[0]*10**3+e[1])
        else:
          heapq.heappush(edgelist,(ans)*10**13+(e[0]+cur)*10**3+e[1])
  return d
Ans=[[] for i in range(n)]
for i in range(n):
  Ans[i]=f(i)
q=int(input())
for _ in range(q):
  s,t=map(int,input().split())
  print(-1 if Ans[s-1][t-1]==float("inf") else Ans[s-1][t-1])
Problem p02926 (python)

Fixed submission:
import math
n=int(input())
def f(x,y):
  return math.atan2(y,x)
  
XY=[]
for i in range(n):
  x,y=map(int,input().split())
  XY.append((x,y,f(x,y)))
XY.sort(key=lambda x:x[2])

def dis(x,y):
  return (x**2+y**2)**0.5
ans=0
for i in range(n):
  for j in range(1,n+1):
    x,y=0,0
    if i+j<=n:
      for k in range(i,i+j):
        x+=XY[k][0]
        y+=XY[k][1]
      ans=max(ans,dis(x,y))
    else:
      for k in range(i,n):
        x+=XY[k][0]
        y+=XY[k][1]
      for k in range(j-(n-i)):
        x+=XY[k][0]
        y+=XY[k][1]
      ans=max(ans,dis(x,y))
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
XY=[]
for i in range(n):
  XY.append([int(i) for i in input().split()])
ans=0
def dis(X):
  return (X[0]**2+X[1]**2)**0.5
for i in range(n):
  A=[dis(XY[i])]
  x1,y1=XY[i][0],XY[i][1]
  for j in range(n):
    if j==i:
      continue
    else:
      x2,y2=XY[j][0],XY[j][1]
      A.append((x1*x2+y1*y2)/A[0])
  ans1,ans2=0,0
  for k in range(n):
    if A[k]>=0:
      ans1+=A[k]
    else:
      ans2-=A[k]
  ans=max([ans,ans1,ans2])
print(ans)
Problem p02941 (python)

Fixed submission:
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]

from heapq import heappop, heappush
push = lambda x,i: heappush(BB,(-x,i))
BB=[]

for i,b in enumerate(B):
  push(b,i)

ans=0
while BB:
  b,ind=heappop(BB)
  b,ai=-b,A[ind]
  if b<ai:
    ans=-1
    break
  d=B[(ind-1)%n]+B[(ind+1)%n]
  dd=(b-ai)//d
  if dd==0:
    if b==ai:
      continue
    ans=-1
    break
  ans+=dd
  B[ind]-=d*dd
  push(b-d*dd,ind)
  
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]

from heapq import heappop, heappush
push = lambda x,i: heappush(BB,(-x,i))
BB=[]

for i,b in enumerate(B):
  push(b,i)

ans=0
while BB:
  b,ind=heappop(BB)
  b,ai=-b,A[ind]
  if b<ai:
    ans=-1
    break
  if ind==0:
    d=B[1]+B[-1]
  elif ind==n-1:
    d=B[-2]+B[0]
  else:
    d=B[ind-1]+B[ind+1)]
  dd=(b-ai)//d
  if dd==0:
    if b==ai:
      continue
    ans=-1
    break
  ans+=dd
  B[ind]-=d*dd
  push(B[ind],ind)
  
print(ans)
Problem p02958 (python)

Fixed submission:
n=int(input())
P=[int(i) for i in input().split()]
ct=0
for i in range(n):
  if i+1!=P[i]:
    ct+=1
print("YES" if ct<=2 else "NO")

Buggy submission (verdict: Runtime Error):
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
ct=0
for i in range(n):
  if i+1!=P[i]:
    ct+=1
print("YES" if ct<=2 else "NO")
Problem p02960 (python)

Fixed submission:
mod=10**9+7
s=input()
n=len(s)
R=[[[0]*13 for _ in range(10)] for __ in range(13)]
for i in range(13):
  for j in range(10):
    for k in range(13):
      R[i][j][k]=(k-i*j)%13

P=[0]*(n+1)
P[0]=1
for i in range(n):
  P[i+1]=(P[i]*10)%13

DP=[[0]*13 for _ in range(n+1)]
DP[0][0]=1
for i in range(n):
  r=P[n-1-i]
  if s[i]=="?":
    for k in range(13):
      DP[i+1][k]=sum(DP[i][R[r][j][k]] for j in range(10))
      DP[i+1][k]%=mod
  else:
    for k in range(13):
      DP[i+1][k]=DP[i][R[r][int(s[i])][k]]
      DP[i+1][k]%=mod
print(DP[n][5]%mod)

Buggy submission (verdict: Runtime Error):
import sys
input=lambda: sys.stdin.readline().rstrip()
mod=10**9+7
a,b,n=map(int,input().split())
def primes(x):
  is_prime=[True]*(x+1)
  is_prime[0]=False
  is_prime[1]=False
  for i in range(2,int(x**0.5)+1):
    if not is_prime[i]:
      continue
    for j in range(i*2,x+1,i):
      is_prime[j]=False
  return [i for i in range(x+1) if is_prime[i]]
P=primes(b)
ans=1
for p in P:
  ord=1
  ord_p=0
  while True:
    ct=b//(p**ord)-(a-1)//(p**ord)
    if ct:
      ord_p+=pow(ct,n,mod-1)
      ord+=1
    else:
      break
  ord_p%=mod-1
  ans=(ans*(pow(p,ord_p,mod)))%mod
print(ans)
Problem p02972 (python)

Fixed submission:
n=int(input())

A=[int(i) for i in input().split()]
Ans=[]
C=[False]*n
for i in reversed(range(n)):
  if A[i]==1:    
    if 2*(i+1)>n:
      Ans.append(i+1)
      C[i]=True
    else:
      c=0
      j=2
      while j*(i+1)<=n:
        if C[j*(i+1)-1]==True:
          c^=1
        j+=1
      if c==0:
        Ans.append(i+1)
        C[i]=True
        
  elif A[i]==0:    
    c=0
    j=2
    while j*(i+1)<=n:
      if C[j*(i+1)-1]==True:
        c^=1
      j+=1
    if c==1:
      Ans.append(i+1)
      C[i]=True
      
if len(Ans)==0:
  print(0)
else:
  print(len(Ans))
  Ans.sort()
  print(*Ans)

Buggy submission (verdict: Runtime Error):
def primes(x):
  is_prime = [True] * (x + 1)
  is_prime[0] = False
  is_prime[1] = False
  for i in range(2, int(x**0.5) + 1):
    if not is_prime[i]:
      continue
    for j in range(i * 2, x + 1, i):
      is_prime[j] = False
  return [i for i in range(x + 1) if is_prime[i]]

n=int(input())
P=primes(n)
A=[int(i) for i in input().split()]
Ans=[]
C=[False]*n
for i in reversed(range(n)):
  if A[i]==1:    
    if 2*(i+1)>n:
      Ans.append(i+1)
      C[i]=True
    else:
      c=1
      j=0
      while P[j]*(i+1)<=n:
        if C[P[j]*(i+1)-1]==True:
          c^=1
        j+=1
      if c==1:
        Ans.append(i+1)
        C[i]=True
  elif A[i]==1:    
    c=0
    j=0
    while P[j]*(i+1)<=n:
      if C[P[j]*(i+1)-1]==True:
        c^=1
      j+=1
    if c==1:
      Ans.append(i+1)
      C[i]=True
if len(Ans)==0:
  print(0)
else:
  print(len(Ans))
  Ans.sort()
  print(*Ans)
Problem p03006 (python)

Fixed submission:
import itertools
import collections
n=int(input())
X=[]
for i in range(n):
  X.append([int(i) for i in input().split()])
X.sort(key=lambda x:(x[0],x[1]))
Y=[]
for c in itertools.combinations(range(n),2):
  x1,y1,x2,y2=X[c[0]][0],X[c[0]][1],X[c[1]][0],X[c[1]][1]
  Y.append((x2-x1,y2-y1))
yy=collections.Counter(Y)
print(1 if n==1 else n-yy.most_common()[0][1])

Buggy submission (verdict: Runtime Error):
import itertools
import collections
n=int(input())
X=[]
for i in range(n):
  X.append([int(i) for i in input().split()])
X.sort(key=lambda x:(x[0],x[1]))
Y=[]
for c in itertools.combinations(range(n),2):
  x1,y1,x2,y2=X[c[0]][0],X[c[0]][1],X[c[1]][0],X[c[1]][1]
  Y.append((x2-x1,y2-y1))
yy=collections.Counter(Y)
print(n-yy.most_common()[0][1])
Problem p03040 (python)

Fixed submission:
from heapq import heappop
from heapq import heappush
q=int(input())
L,R=[],[]
b_sum=0
l_sum,r_sum=0,0
count=0
mid=0
for _ in range(q):
  
  Q=list(map(int,input().split()))
  if Q[0]==1:
    a,b=Q[1],Q[2]
    count+=1
    b_sum+=b
    if count==1:
      mid=a
    elif count%2==0:
      if a<=mid:
        heappush(L,-a)
        l_sum+=a
        heappush(R,mid)
        r_sum+=mid
      else:
        heappush(L,-mid)
        l_sum+=mid
        heappush(R,a)
        r_sum+=a
    else:
      l,r=-heappop(L),heappop(R)
      if a<l:
        heappush(L,-a)
        l_sum+=a-l
        mid=l
        heappush(R,r)
      elif r<a:
        heappush(L,-l)
        mid=r
        heappush(R,a)
        r_sum+=a-r
      else:
        heappush(L,-l)
        mid=a
        heappush(R,r)

  else:
    if count%2==1:
      print(mid,r_sum-l_sum+b_sum)
    else:
      l=-heappop(L)
      print(l,r_sum-l_sum+b_sum)
      heappush(L,-l)

Buggy submission (verdict: Runtime Error):
from heapq import heappop
from heapq import heappush
q=int(input())
L,R=[],[]
b_sum=0
l_sum,r_sum=0,0
count=0
mid=0
for _ in range(q):
  
  Q=list(map(int,input().split()))
  if Q[0]==1:
    a,b=Q[1],Q[2]
    count+=1
    b_sum+=b
    if count==1:
      mid=a
    elif count%2==0:
      if a<=mid:
        heappush(L,-a)
        l_sum+=a
        heappush(R,mid)
        r_sum+=mid
      else:
        heappush(L,-mid)
        l_sum+=mid
        heappush(R,a)
        r_sum+=a
    else:
      l,r=-heappop(L),heappop(R)
      if a<l:
        heappush(L,-a)
        l_sum+=a-l
        mid=l
        heappush(R,r)
      elif r<a:
        heappush(L,-l)
        mid=r
        heappush(R,a)
        r_sum+=a-r
      else:
        heappush(L,-l)
        mid=a
        heappush(R,r)

  else:
    if count%2==1:
      print(mid,r_sum-l_sum+b_sum)
    else:
      print(-heappop(L),r_sum-l_sum+b_sum)
Problem p03046 (python)

Fixed submission:
m,k=map(int,input().split())
if m==0 and k==0:
  print(0,0)
elif m==1 and k==1:
  print(-1)
elif k>2**m-1:
  print(-1)
elif k==2**m-1:
  Ans=[]
  for i in range(2**m-1):
    Ans.append(2**m-2-i)
  Ans.append(2**m-1)
  for i in range(2**m):
    Ans.append(i)
  print(*Ans)
else:
  if k==0:
    Ans=[]
    for i in range(2**m):
      Ans.append(i)
      Ans.append(i)
    print(*Ans)
  else:
    Ans=[k]
    for i in range(2**m):
      if i!=k:
        Ans.append(i)
    Ans.append(k)
    for i in range(2**m):
      if i!=2**m-1-k:
        Ans.append(2**m-1-i)
    print(*Ans)

Buggy submission (verdict: Runtime Error):
m,k=map(int,input().split())
if k>=2**m-1:
  print(-1)
else:
  if k==0:
    Ans=[]
    for i in range(2**m):
      Ans.append(i)
      Ans.append(i)
    print(*Ans)
  else:
    Ans=[k]
    for i in range(2**m):
      if i!=k:
        Ans.append(i)
    Ans.append(k)
    for i in range(2**m):
      if i!=k
        Ans.append(2**m-1-i)
    print(*Ans)
Problem p03047 (python)

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

Buggy submission (verdict: Runtime Error):
n,k=map(int,input(),split())
print(n-k+1)
Problem p03048 (python)

Fixed submission:
r,g,b,n=map(int,input().split())
ans=0
for i in range(n//r+1):
  for j in range(n//g+1):
    if (n-i*r-j*g)%b==0 and (n-i*r-j*g)//b>=0:
      ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
r,g,b,n=map(int,input().split())
ans=0
for i in range(n//r+1):
  for j inr range(n//g+1):
    if (n-i*r-j*g)%b==0 and (n-i*r-j*g)//b>=0:
      ans+=1
print(ans)