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

Fixed submission:
a,b,c=input().split(",")
print(a,b,c)

Buggy submission (verdict: Runtime Error):
S=input()
print(S,replace(',',' ')
Problem p03835 (python)

Fixed submission:
K,S=map(int,input().split())
cnt=0

for i in range(K+1):
  for j in range(K+1):
    k=S-(i+j)
    if (k>=0) and (k<=K):
      cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
K,S=map(int,input().split())
cnt=0
K+=1
for i in range(K):
  for j in range(K):
    k=S-(i+j)
    if (S>=0) and (S<=K)
      cnt+=1
print(cnt)
Problem p02546 (python)

Fixed submission:
s=str(input())
s=list(s)
if s[len(s)-1]=="s":
  print("".join(s)+"es")
else:
  print("".join(s)+"s")

Buggy submission (verdict: Runtime Error):
s=str(input())
s=list(s)
if s[len(s)-1]=="s":
  print("".join(s)+"es")
else:
  print("".join()+"s")
Problem p02580 (python)

Fixed submission:
h,w,m=map(int,input().split())
s=[0]*m
t=[0]*m
temp=set()
for i in range(m):
  sm,tm=map(int,input().split())
  s[i]=sm
  t[i]=tm
  temp.add((s[i],t[i]))
st=[0]*h
tt=[0]*w
for i in range(m):
  st[s[i]-1]=st[s[i]-1]+1
  tt[t[i]-1]=tt[t[i]-1]+1
smax=max(st)
tmax=max(tt)
ans=smax+tmax
maxs=[]
maxt=[]
for i in range(h):
  if st[i]==smax:
    maxs.append(i)
for i in range(w):
  if tt[i]==tmax:
    maxt.append(i)

if len(maxs)*len(maxt)>m:
  print(ans)
else:
  for i in range(len(maxs)):
    for j in range(len(maxt)):
      if (maxs[i]+1,maxt[j]+1) not in temp:
        print(ans)
        exit()
  else:
    print(ans-1)

Buggy submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
s=[0]*m
t=[0]*m
temp=[]*m
for i in range(m):
  sm,tm=map(int,input().split())
  s[i]=sm
  t[i]=tm
  temp[i]=[s[i],t[i]]
st=[0]*h
tt=[0]*w
for i in range(m):
  st[s[i]-1]=st[s[i]-1]+1
  tt[t[i]-1]=tt[t[i]-1]+1
smax=max(st)
tmax=max(tt)
ans=smax+tmax
maxs=[]
maxt=[]
for i in range(h):
  if st[i]==smax:
    maxs.append(i)
for i in range(w):
  if tt[i]==tmax:
    maxt.append(i)

if len(maxs)*len(maxt)>m:
  print(ans)
else:
  for i in range(len(maxs)):
    for j in range(len(maxt)):
      if (maxs[i]+1,maxt[j]+1) not in temp:
        print(ans)
        exit()
  else:
    print(ans-1)

Buggy submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
s=[0]*m
st=[0]*m
t=[0]*m
tt=[0]*m
for i in range(m):
  sm,tm=map(int,input().split())
  s[i]=sm
  st[i]=sm
  t[i]=tm
  tt[i]=tm
  
import statistics
temp=statistics.mode(s)
ans1=s.count(temp)
for i in range(m):
  if s[i]==temp:
    tt[i]=999999999999999999
while 999999999999999999 in tt:tt.remove(999999999999999999)
temp=statistics.mode(tt)
ans1=ans1+tt.count(temp)

temp=statistics.mode(t)
ans2=t.count(temp)
for i in range(m):
  if t[i]==temp:
    st[i]=999999999999999999
while 999999999999999999 in st:st.remove(999999999999999999)
temp=statistics.mode(st)
ans2=ans2+st.count(temp)

print(max(ans1,ans2))
Problem p02598 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
tmax=max(a)
tmin=0
import math
ans=tmax
if k==0:
  print(tmax)
else:
  while True:
    t=(tmax+tmin)//2
    if abs(tmax-tmin)<=1:
      break
    s=0
    for i in range(n):
      s=s+math.ceil(a[i]/t)-1
    if k>=s:
      ans=min(math.ceil(t),ans)
      tmax=t
    else:
      tmin=t
  print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
tmax=max(a)
tmin=0
t=(tmax+tmin)//2
import math
ans=tmax
if k==0:
  print(tmax)
else:
  while True:
    s=0
    for i in range(n):
      s=s+math.ceil(a[i]/t)-1
    if k>=s:
      ans=min(math.ceil(t),math.ceil(ans))
      tmax=t
      t=(tmin+t)//2
    else:
      tmin=t
      t=(t+tmax)//2
    if tmax-tmin<0.01:
      break
  print(ans)
Problem p02659 (python)

Fixed submission:
A,B = map(str,input().split())
A = int(A)
B = int(float(B)*1000)
print(int(A*B)//1000)

Buggy submission (verdict: Runtime Error):
a,b=map(str,input().split())
temp=eval(b)*100
print(int(a*temp))
Problem p02688 (python)

Fixed submission:
n,k = map(int, input().split())
di=[0]*k
Ap=[0]*n
for i in range(0,k):
    di[i] = int(input())
    A = list(map(int, input().split()))
    ai=0
    A.append(-100)
    for j in range(1,n+1):
        if A[ai]==j:
            ai=ai+1
            Ap[j-1]=1
num=0
for l in range(0,n):
    if Ap[l]==0:
        num=num+1
print(num)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())
di=[0]*k
Ap=[0]*n
for i in range(0,k):
    di[i] = int(input())
    A = list(map(int, input().split()))
    ai=0
    for j in range(1,n+1):
        if A[ai]==j:
            ai=ai+1
            Ap[j-1]=1
num=0
for l in range(0,n):
    if Ap[l]==0:
        num=num+1
print(num)
Problem p02701 (python)

Fixed submission:
n=int(input())
s=[0]*n
for i in range(n):
  s[i]=str(input())
s=list(set(s))
print(len(s))

Buggy submission (verdict: Runtime Error):
n=int(input())
s=[]
for i in range(n):
  s[i]=str(input())
s=list(set(s))
print(len(s))
Problem p02725 (python)

Fixed submission:
k,n=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
temp=a[0]+k-a[n-1]
for i in range(1,n):
  temp=max(temp,a[i]-a[i-1])
print(k-temp)

Buggy submission (verdict: Runtime Error):
k,n=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
temp=a[0]+a[n-1]
for i in range(1,n):
  temp=max(temp,a[i]-i[i-1])
print(k-temp)

Buggy submission (verdict: Runtime Error):
k,n=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
temp=a[0]+a[n-1]
for i in range(1,n):
  temp=max(ans,a[i]-i[i-1])
print(k-temp)
Problem p02735 (python)

Fixed submission:
h,w=map(int,input().split())
s=[0]*h
t=[0]*h
for i in range(h):
  st=str(input())
  st=list(st)
  s[i]=st
  tt=[0]*w
  t[i]=tt
if s[0][0]=="#":
  t[0][0]=1
for i in range(1,h):
  t[i][0]=t[i-1][0]
  if s[i-1][0]=="." and s[i][0]=="#":
    t[i][0]=t[i-1][0]+1
for i in range(1,w):
  t[0][i]=t[0][i-1]
  if s[0][i-1]=="." and s[0][i]=="#":
    t[0][i]=t[0][i-1]+1
for i in range(1,w):
  for j in range(1,h):
    if s[j-1][i]=="." and s[j][i]=="#":
      t1=t[j-1][i]+1
    else:
      t1=t[j-1][i]
    if s[j][i-1]=="." and s[j][i]=="#":
      t2=t[j][i-1]+1
    else:
      t2=t[j][i-1]
    t[j][i]=min(t1,t2)
print(t[h-1][w-1])

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
s=[0]*h
t=[0]*h
for i in range(h):
  st=str(input())
  st=list(st)
  s[i]=st
  tt=[0]*w
  t[i]=tt
if s[0][0]=="#":
  t[0][0]=1
for i in range(1,w):
  t[i][0]=t[i-1][0]
  if s[i][0]=="#":
    t[i][0]=t[i-1][0]+1
for i in range(1,h):
  t[0][i]=t[0][i-1]
  if s[0][i]=="#":
    t[0][i]=t[0][i-1]+1
for i in range(1,h):
  for j in range(1,w):
    t[j][i]=min(t[j-1][i],t[j][i-1])
    if s[j][i]=="#":
      t[j][i]=t[j][i-1]+1
print(t[w-1][h-1])
Problem p02836 (python)

Fixed submission:
a=str(input())
a=list(a)
count=0
for i in range(0,int(len(a)/2)):
    if a[i]!=a[len(a)-i-1]:
        count=count+1
  
print(count)

Buggy submission (verdict: Runtime Error):
a=str(input())
a=list(a)
count=0
if a%2 == 0:
  for i in range(0,int(a/2)):
    if a[i]==a[len(a)-i-1]:
      count=count+1
else:
  for i in range(0,int(a/2)):
    if a[i]==a[len(a)-i-1]:
      count=count+1
  
print(count)
Problem p02880 (python)

Fixed submission:
n=int(input())
for i in range(1,10):
  if n%i==0:
    if n/i>=1 and n/i<=9:
      print("Yes")
      break
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
for i in range(0,9):
  if n%i==0:
    if n/i>=1 and n/i<=9:
      print("Yes")
      break
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
for i in range(0,9):
  if n%i==0 and n/i>=1 and n/i<=9:
    print("Yes")
    break
else:
  print("No")
Problem p02912 (python)

Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
  a[i]=a[i]*-1
import heapq
heapq.heapify(a)
for i in range(m):
  t=(heapq.heappop(a))*-1
  heapq.heappush(a,(t//2)*-1)
print(sum(a)*-1)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
for i in range(m):
  a[0]=a[0]/2
  for j in range(1,n):
    if a[0]>a[j]:
      a.insert(j,a[0])
      del a[0]
      break
  print(a)
import math
ans=0
for i in range(n):
  ans=ans+math.floor(a[i])
print(ans)
Problem p03013 (python)

Fixed submission:
n,m=map(int,input().split())
a=[0]*m
for i in range(m):
  a[i]=int(input())
a.append(0)
temp=[0]*(n+1)
temp[0]=1
if 1 in a:
  temp[1]=0
  j=1
else:
  temp[1]=1
  j=0
for i in range(2,n+1):
  if a[j]==i:
    temp[i]=0
    j=j+1
  else:
    temp[i]=temp[i-2]+temp[i-1]
    temp[i]=temp[i]%(10**9+7)
print(temp[n])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[0]*m
for i in range(m):
  a[i]=int(input())
temp=[0]*(n+1)
temp[0]=1
if a[0]==1:
  temp[1]=0
else:
  temp[1]=1
for i in range(2,n+1):
  if i in a:
    temp[i]=0
  else:
    temp[i]=temp[i-2]+temp[i-1]
    temp[i]=temp[i]%(10**9+7)
print(temp[n])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[0]*m
for i in range(m):
  a[i]=int(input())
temp=[0]*(n+1)
temp[0]=1
if a[i]==1:
  temp[1]=0
else:
  temp[1]=1
for i in range(2,n+1):
  if i in a:
    temp[i]=0
  else:
    temp[i]=temp[i-2]+temp[i-1]
    temp[i]=temp[i]%(10**9+7)
print(temp[n])
Problem p03017 (python)

Fixed submission:
n,a,b,c,d=map(int,input().split())
s=str(input())
s=list(s)
cnts=0
cnti=0
space=0
iwa=0
temp=0
next=0
if c<d:
  for i in range(a-1,d):
    if s[i]==".":
      cnts=cnts+1
      space=max(space,cnts)
      cnti=0
    else:
      cnti=cnti+1
      iwa=max(iwa,cnti)
      cnts=0
  if iwa>1:
    print("No")
  else:
    print("Yes")
else:
  for i in range(a-1,c):
    if s[i]==".":
      if i<=b-2:
        cnts=0
      cnts=cnts+1
      space=max(space,cnts)
      cnti=0
    else:
      cnti=cnti+1
      iwa=max(iwa,cnti)
      cnts=0
    if i==d-1:
      temp=space
      if s[i-1]=="." and s[i+1]==".":
        next=1
  if iwa>1:
    print("No")
  elif temp<3 and next==0:
    print("No")
  else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
n,a,b,c,d=map(int,input().split())
s=str(input())
s=list(s)
cnts=0
cnti=0
space=0
iwa=0
temp=0
next=0
if c<d:
  for i in range(a-1,max(c,d)):
    if s[i]==".":
      cnts=cnts+1
      space=max(space,cnts)
      cnti=0
    else:
      cnti=cnti+1
      iwa=max(iwa,cnti)
      cnts=0
  if iwa>1:
    print("No")
  else:
    print("Yes")
else:
  for i in range(a-1,max(c,d)):
    if i==d:
      temp=space
      if s[i-1]=="." and s[i+1]==".":
        next=1
    if s[i]==".":
      cnts=cnts+1
      space=max(space,cnts)
      cnti=0
    else:
      cnti=cnti+1
      iwa=max(iwa,cnti)
      cnts=0
  if iwa>1:
    print("No")
  elif temp<3 and next==0:
    print("No")
  else:
    print("Yes")
Problem p03041 (python)

Fixed submission:
n,k=map(int,input().split())
s=str(input())
s=list(s)
s[k-1]=str.lower(s[k-1])
print("".join(s))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=str(input())
s=list(s)
s[k-1]=str.lower(s[k-1])
print("".join(s))n,k=map(int,input().split())
s=str(input())
s=list(s)
s[k-1]=str.lower(s[k-1])
print("".join(s))
Problem p03209 (python)

Fixed submission:
n,x=map(int,input().split())
p=[1]
a=[1]
for i in range(0,n):
  p.append(p[i]*2+1)
  a.append(a[i]*2+3)
def f(n,x):
  if n==0 and x<=0:
    return 0
  elif n==0:
    return 1
  elif x<=1+a[n-1]:
    return f(n-1,x-1)
  else:
    return p[n-1]+f(n-1,x-a[n-1]-2)+1
print(f(n,x))

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
p=[1]
a=[1]
for i in range(0,n-1):
  p.append(p[i]*2+1)
  a.append(a[i]*2+3)
def f(n,x):
  if x==1:
    return 0
  elif x<=1+a[n-1]:
    return f(n-1,x-1)
  else:
    return p[n-1]+f(n-1,x-a[n-1]-2)+1
print(f(n,x))
Problem p03252 (python)

Fixed submission:
s=str(input())
t=str(input())
temp=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
s=list(s)
t=list(t)
temps=[0]*len(temp)
tempt=[0]*len(temp)
for i in range(0,len(temp)):
  temps[i]=s.count(temp[i])
  tempt[i]=t.count(temp[i])
temps.sort()
tempt.sort()
if temps==tempt:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s=str(input())
t=str(input())
temps=list(set(s))
tempt=list(set(t))
temps=sorted(temps)
tempt=sorted(tempt)
for i in range(0,len(temps)):
  temps1[i]=s.count(temps[i])
for i in range(0,len(tempt)):
  tempt1[i]=t.count(tempt[i])
if temps1==tempt1:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s=str(input())
t=str(input())
temps=list(set(s))
tempt=list(set(t))
temps=sorted(list(temps))
tempt=sorted(list(tempt))
for i in range(0,len(temps)):
  temps[i]=s.count(temps[i])
for i in range(0,len(tempt)):
  tempt[i]=t.count(tempt[i])
count=0
for i in range(0,len(temps)):
  if temps[i]==tempt[i]:
    count=count+1
if count==len(temps):
  print("Yes")
else:
  print("No")
Problem p03329 (python)

Fixed submission:
n = int(input())
count=n
for i in range(0,n+1):
  temp=0
  temp6=i
  while temp6>0:
    temp=temp+temp6%6
    temp6=int(temp6/6)
  temp9=n-i
  while temp9>0:
    temp=temp+temp9%9
    temp9=int(temp9/9)
  count=min(count,temp)
print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
count=0
while n>=5:
  temp=[]
  i=1
  while n>=6**i:
    temp.append(6**i)
    i=i+1
  i=1
  while n>=9**i:
    temp.append(9**i)
    i=i+1
  n=n-max(temp)
  count=count+1
print(count+n)
Problem p03835 (python)

Fixed submission:
k,s=map(int,input().split())
temp=[1 for y in range(k+1) for x in range(k+1) if 0<=s-x-y<=k]
print(len(temp))

Buggy submission (verdict: Runtime Error):
k,s=map(int,input().split())
x=[0]*k
for i in range(0,k):
  x[i]=i
x.append(k)
a=int(s/3)-1
count=0
for i in range(0,len(x)):
  stemp=s-x[i]
  for j in range(0,stemp+1):
    if s-x[i]-x[j] in x:
      count=count+1
print(count)
Problem p02572 (python)

Fixed submission:
mod = 10 ** 9 + 7
n = int(input())

a_sum = 0
sq_sum = 0
for a in map(int, input().split()):
  a_sum = (a_sum + a) % mod
  sq_sum = (sq_sum + a * a) % mod
res = (a_sum * a_sum - sq_sum) % mod
print(-(mod // 2) % mod * res % mod)

Buggy submission (verdict: Runtime Error):
mod = 10 ** 9 + 7
n = int(input())

a_sum = 0
sq_sum = 0
for a in map(int, input().split()):
  a_sum = (a_sum + a) % mod
  sq_sum = (sq_sum + a * a) % mod
res = (a_sum * a_sum - sq_sum) % mod
print(-(p // 2) % mod * res % mod)
Problem p02659 (python)

Fixed submission:
a, b = input().split()
a = int(a)
bx100 = int(b.replace('.', ''))
print(a * bx100 // 100)

Buggy submission (verdict: Runtime Error):
a, b = input().split()
a = int(a)
bx100 = int(b.repleace('.', ''))
print(a * bx100 // 100)
Problem p02753 (python)

Fixed submission:
s = input()
if s == 'AAA' or s == 'BBB':
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
x = []
for i in range(1000):
  x.append([0] * 10000000000000)
Problem p02757 (python)

Fixed submission:
n, p = map(int, input().split())
s = input()
count = 0
if p == 2 or p == 5:
  for i in range(n):
    if int(s[i]) % p == 0:
      count += i + 1
  print(count)
else:
  mod = [0] * p
  mod[0] = 1
  tmp = 0
  ten = 1
  for i in s[::-1]:
    ten = ten * 10 % p
    tmp = (tmp + int(i) * ten) % p
    mod[tmp] += 1
  for m in mod:
    count += m * (m - 1) // 2
  print(count)

Buggy submission (verdict: Runtime Error):
n, p = map(int, input().split())
s = input()
count = 0
if p == 2 or p == 5:
  for i in s:
    if int(i) % p == 0:
      count += i + 1
  print(count)
else:
  mod = [0] * p
  mod[0] = 1
  tmp = 0
  ten = 1
  for i in s[::-1]:
    ten = ten * 10 % p
    tmp = (tmp + int(i) * ten) % p
    mod[tmp] += 1
  for m in mod:
    count += m * (m - 1) // 2
  print(count)

Buggy submission (verdict: Runtime Error):
n, p = map(int, input().split())
s = input()
count = 0
if p == 2 or p == 5:
  for i in s:
    if int(i) % p == 0:
      count += i + 1
  print(count)
else:
  mod = [0] * p
  mod[0] = 1
  tmp = 0
  ten = 1
  for i in s[::-1]:
    ten = ten * 10 % p
    tmp = (tmp + int(i) * ten) % p
    mod[tmp] += 1
  for m in mod:
    count += m * (m - 1) // 2
  print(count)

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

n, p = map(int, input().split())
s = np.array([int(i) % p for i in input()])
mod = np.zeros((n, p), dtype=np.int)
for i in range(n):
  mod[i, s[i]] = 1
count = mod[0, 0]
for i in range(1, n):
  idx = s[i]
  for j in range(p):
    mod[i, idx] += mod[i-1, j]
    idx = (idx + 10) % p
print(mod[:, 0].sum())

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

n, p = map(int, input().split())
s = np.array([int(i) % p for i in input()])
mod = np.zeros((n, p), dtype=np.int)
for i in range(n):
  mod[i, s[i]] = 1
count = mod[0, 0]
for i in range(1, n):
  idx = s[i]
  for j in range(p):
    mod[i, idx] += mod[i-1, j]
    idx = (idx + 10) % p
print(mod[:, 0].sum())

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

n, p = map(int, input().split())
s = np.array([int(i) % p for i in input()])
mod = np.zeros((n, p), dtype=np.int)
for i in range(n):
  mod[i, s[i]] = 1
count = mod[0, 0]
for i in range(1, n):
  idx = s[i]
  for j in range(p):
    mod[i, idx] += mod[i-1, j]
    idx = (idx + 10) % p
print(mod[:, 0].sum())

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

n, p = map(int, input().split())
s = np.array([int(i) % p for i in input()])
mod = np.zeros((n, p), dtype=np.int)
for i in range(n):
  mod[i, s[i]] = 1
count = mod[0, 0]
for i in range(1, n):
  idx = s[i]
  for j in range(p):
    mod[i, idx] += mod[i-1, j]
    idx = (idx + 10) % mod
print(mod[:, 0].sum())
Problem p02759 (python)

Fixed submission:
n = int(input())
print((n+1) // 2)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())

friend = [[] for _ in range(n)]
block = [[] for _ in range(n)]

for _ in range(m):
  a, b = map(int, input().split())
  friend[a-1].append(b-1)
  friend[b-1].append(a-1)
  
for _ in range(k):
  c, d = map(int, input().split())
  block[c-1].append(d-1)
  block[d-1].append(c-1)
  
groups = []
active = [True] * n
belong = [0] * n
g_index = 0
while any(active):
  idx = active.index(True)
  g = [idx]
  active[idx] = False
  belong[idx] = g_index
  stack = [idx]
  while stack:
    v = stack.pop()
    for i in friend[v]:
      if active[i]:
        stack.append(i)
        active[i] = False
        belong[i] = g_index
        g.append(i)
  groups.append(g)
  g_index += 1
  
for i in range(n):
  size = len(groups[belong[i]]) - 1
  for j in groups[belong[i]]:
    if j in friend[i] or j in block[i]:
      size -= 1
  print(size, end=' ')
Problem p02762 (python)

Fixed submission:
class UnionFind:
  def __init__(self, n: int):
    self.parent = list(range(n))
    self.size = [1] * n
    self.rank = [1] * n
    
  def find(self, i: int) -> int:
    if self.parent[i] != i:
      self.parent[i] = self.find(self.parent[i])
    return self.parent[i]
  
  def unite(self, i: int, j: int):
    ri = self.find(i)
    rj = self.find(j)
    if ri != rj:
      if self.rank[ri] < self.rank[rj]:
        self.parent[ri] = rj
        self.size[rj] += self.size[ri]
      else:
        self.parent[rj] = ri
        self.size[ri] += self.size[rj]
        if self.rank[ri] == self.rank[rj]:
          self.rank[ri] += 1


n, m, k = map(int, input().split())

n_friend = [1 for _ in range(n)]
block = [[] for _ in range(n)]
friendship = UnionFind(n)

for _ in range(m):
  a, b = map(int, input().split())
  n_friend[a-1] += 1
  n_friend[b-1] += 1
  friendship.unite(a-1, b-1)
  
for _ in range(k):
  c, d = map(int, input().split())
  block[c-1].append(d-1)
  block[d-1].append(c-1)
  
for i in range(n):
  r = friendship.find(i)
  cand = friendship.size[r] - n_friend[i]
  for j in block[i]:
    if r == friendship.find(j):
      cand -= 1
  print(cand, end=' ')

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())

friend = [[] for _ in range(n)]
block = [[] for _ in range(n)]

for _ in range(m):
  a, b = map(int, input().split())
  friend[a-1].append(b-1)
  friend[b-1].append(a-1)
  
for _ in range(k):
  c, d = map(int, input().split())
  block[c-1].append(d-1)
  block[d-1].append(c-1)
  
groups = []
active = [True] * n
belong = [0] * n
g_index = 0
while any(active):
  idx = active.index(True)
  g.append([idx])
  active[idx] = False
  belong[idx] = g_index
  stack = [idx]
  while stack:
    v = stack.pop()
    for i in friend[v]:
      if active[i]:
        stack.append(i)
        active[i] = False
        belong[i] = g_index
        g.append(i)
  groups.append(g)
  g_index += 1
  
for i in range(n):
  size = len(groups[belong[i]]) - 1
  for j in groups[belong[i]]:
    if j in friend[i] or j in block[i]:
      size -= 1
  print(size, end=' ')
Problem p02862 (python)

Fixed submission:
x, y = map(int, input().split())
z = x + y
mod = 10 ** 9 + 7
if z % 3 == 0:
  w = z // 3
  a, b = sorted([x - w, y - w])
  if a < 0:
    print(0)
  elif a == 0:
    print(1)
  else:
    inv_mod = [1] * (a + 1)
    num = b + 1
    den = 1
    for i in range(2, a + 1):
      num = num * (b + i) % mod
      inv_mod[i] = -inv_mod[mod % i] * (mod // i) % mod
      den = den * inv_mod[i] % mod
    print(num * den % mod)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
x, y = map(int, input().split())
z = x + y
mod = 10 ** 9 + 7
if z % 3 == 0:
  w = z // 3
  a, b = sorted([x - w, y - w])
  inv_mod = [1] * a
  num = b + 1
  den = 1
  for i in range(2, a + 1):
    num = num * (b + i) % mod
    inv_mod[i] = -(mod // i) * inv_mod[mod % i] % mod
    den = den * inv_mod[i] % mod
  print(num * den % mod)
else:
  print(0)
Problem p02879 (python)

Fixed submission:
a, b = map(int, input().split())
if a < 10 and b < 10:
  print(a * b)
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
f = sorted(map(int, input().split()))
time = [f[i] * a[-i-1] for i in range(n)]

sup = max([time[i] - f[i] * k // n for i in range(n)] + [0])
inf = 0
while sup > inf:
  x = (sup + inf) // 2
  train = sum([(max([0, time[i] - x]) + f[i] - 1) // f[i] for i in range(n)])
  if k < train:
    inf = x + 1
  else:
    sup = x
print(sup)
Problem p02884 (python)

Fixed submission:
import numpy as np

n, m = map(int, input().split())
adj = np.zeros((n, n), dtype=np.bool)
for _ in range(m):
  s, t = map(int, input().split())
  adj[s-1, t-1] = True
deg = adj.sum(axis=1)

ev = np.zeros(n, dtype=np.float)
for i in range(n - 2, -1, -1):
  ev[i] = ev[adj[i]].mean() + 1.

prob = np.zeros(n, dtype=np.float)
prob[0] = 1.
for i in range(n - 1):
  prob[adj[i]] += prob[i] / deg[i]

decrease = 0.
for i in np.where(deg > 1)[0]:
  now = ev[adj[i]].mean()
  cut = (ev[adj[i]].sum() - ev[adj[i]].max()) / (deg[i] - 1)
  decrease = np.maximum(decrease, (now - cut) * prob[i])
    
print(ev[0] - decrease)

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

n, m = map(int, input().split())
adj = np.zeros((n, n), dtype=np.bool)
for _ in range(m):
  s, t = map(int, input().split())
  adj[s-1, t-1] = True
deg = adj.sum(axis=1)

ev = np.zeros(n, dtype=np.float)
for i in range(n - 2, -1, -1):
  ev[i] = ev[adj[i]].mean() + 1.

prob = np.zeros(n, dtype=np.float)
prob[0] = 1.
for i in range(n - 1):
  prob[adj[i]] += prob[i] / deg[i]

decrease = 0.
for i in np.where(deg > 1)[0]:
  now = ev[adj[i]].mean()
  cut = (ev[adj[i]].sum() - ev[adj[i]].max()) / (deg[i] - 1)
  decrease = np.maximum(diff, now - cut)
    
print(ev[0] - decrease)

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

n, m = map(int, input().split())
adj = np.zeros((n, n), dtype=np.bool)
for _ in range(m):
  s, t = map(int, input().split())
  adj[s-1, t-1] = True

dp = np.zeros(n, dtype=np.float)
for i in range(n - 2, -1, -1):
  dp[i] = dp[adj[i]].mean() + 1.
  
ans = dp[0]

for i in np.where(adj.sum(axis=1) > 1)[0]:
  dp_i = dp.copy()
  dp_i[i] = (dp_i[adj[i]].sum() - dp_i[adj[i]].max()) / (adj[i].sum() - 1) + 1
  for j in range(i - 1, -1, -1):
    dp_i[j] = dp_i[adj[j]].mean() + 1
  ans = min[ans, dp_i[0]]
    
print(ans)