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

Fixed submission:
def root(x):
  while par[x]>=0:x=par[x]
  return x
def unite(x,y):
  x,y=root(x),root(y)
  if x!=y:
    if x>y:x,y=y,x
    par[x]+=par[y]
    par[y]=x
def same(x,y):
  return root(x)==root(y)
def size(x):
  return-par[root(x)]
n,m,k,*t=map(int,open(0).read().split())
par=[-1]*n
f=[set()for _ in range(n)]
for a,b in zip(*[iter(t[:m*2])]*2):
  a-=1
  b-=1
  unite(a,b)
  f[a].add(b)
  f[b].add(a)
a=[size(i)-len(f[i])-1for i in range(n)]
for c,d in zip(*[iter(t[m*2:])]*2):
  c-=1
  d-=1
  if same(c,d):
    a[c]-=1
    a[d]-=1
print(*a)

Buggy submission (verdict: Runtime Error):
r=lambda x:p[x]>=0and r(p[x])or x
(n,m,k),*t=[map(int,t.split())for t in open(0)]
p=[-1]*-~n
s=[-1]*-~n
for a,b in t:
 x,y=sorted((r(a),r(b)))
 if(x!=y)*m>0:p[x]+=p[y];p[y]=x
 if m>0or x==y:s[a]-=1;s[b]-=1
 m-=1
print(*[s[i+1]-p[r(i+1)]for i in range(n)])

Buggy submission (verdict: Runtime Error):
r=lambda x:p[x]>=0and r(p[x])or x
(n,m,k),*t=[map(int,t.split())for t in open(0)]
p,f=[-1]*-~n,[-1]*-~n
for a,b in t[:m]:
  x,y=r(a),r(b)
  if x!=y:
    if x>y:x,y=y,x
    p[x]+=p[y]
    p[y]=x
  f[a]-=1,
  f[b]-=1,
a=[f[i]-p[r(i)]for i in range(n+1)]
for c,d in t[m:]:
  if r(c)==r(d):
    a[c]-=1
    a[d]-=1
print(*a[1:])

Buggy submission (verdict: Runtime Error):
r=lambda x:p[x]>=0and r(p[x])or x
(n,m,k),*t=[map(int,t.split())for t in open(0)]
p=[-1]*-~n
f=[[]for _ in p]
for a,b in t[:m]:
  x,y=r(a),r(b)
  if x!=y:
    p[x]+=p[y]
    p[y]=x
  f[a]+=b,
  f[b]+=a,
a=[~len(f[i])-p[r(i)]for i in range(n+1)]
for c,d in t[m:]:
  if r(c)==r(d):
    a[c]-=1
    a[d]-=1
print(*a[1:])
Problem p02763 (python)

Fixed submission:
import sys
input=sys.stdin.buffer.readline
n=int(input())+1
data=[0]*n*2
def update(i,x):
  i+=n
  data[i]=x
  i//=2
  while i:
    data[i]=data[i*2]|data[i*2+1]
    i//=2
def query(l,r):
  l+=n
  r+=n
  s=0
  while l<r:
    if l&1:
      s|=data[l]
      l+=1
    if r&1:
      r-=1
      s|=data[r]
    l//=2
    r//=2
  return sum(map(int,bin(s)[2:]))
for i,c in enumerate(input()[:-1]):
  update(i,2**(c-97))
for _ in range(int(input())):
  q,a,b=input().split()
  if q[0]>49:print(query(int(a)-1,int(b)))
  else:update(int(a)-1,2**(b[0]-97))

Buggy submission (verdict: Runtime Error):
def main():
  import sys
  b=sys.stdin.buffer
  n=int(b.readline())
  d=[0]*n+[1<<c-97for c in b.readline()[:n]]
  for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i]
  r=[]
  for q,a,b in zip(*[iter(b.read().split())]*3):
    i,s=int(a)+n-1,0
    if q<b'2':
      d[i]=1<<b[0]-97
      while i:
        i//=2
        d[i]=d[i+i]|d[i-~i]
      continue
    j=int(b)+n
    while i<j:
      if i&1:
        s|=d[i]
        i+=1
      if j&1:
        j-=1
        s|=d[j]
      i//=2
      j//=2
    r+=bin(s).count('1'),
  print(' '.join(map(str,r)))
main()

Buggy submission (verdict: Runtime Error):
def main():
  import sys
  from numpy import zeros
  input=sys.stdin.buffer.readline
  n=int(input())+1
  #data=zeros((n*2,26),int)
  data=[zeros(26,int)for _ in range(26)]
  def update(i,x):
    i+=n
    d=data[i]
    d[:]=0
    d[x]=1
    i//=2
    while i:
      data[i]=data[i*2]|data[i*2+1]
      i//=2
  def query(l,r):
    l+=n
    r+=n
    s=zeros(26,int)
    while l<r:
      if l&1:
        s|=data[l]
        l+=1
      if r&1:
        r-=1
        s|=data[r]
      l//=2
      r//=2
    return s.sum()
  for i,c in enumerate(input()[:-1],n):data[i][c-97]=1
  for i in range(n-1,0,-1):data[i]=data[i*2]|data[i-~i]
  s=[]
  for _ in range(int(input())):
    q,a,b=input().split()
    if q[0]>49:s+=query(int(a)-1,int(b)),
    else:update(int(a)-1,b[0]-97)
  print('\n'.join(map(str,s)))
main()
Problem p02766 (python)

Fixed submission:
n,k=map(int,input().split())
c=0
while n:n//=k;c+=1
print(c)

Buggy submission (verdict: Runtime Error):
n,k=input().split();print(len(str(int(n,int(k)))))
Problem p02777 (python)

Fixed submission:
s,t,a,b,u=open(0).read().split();i=u==s;print(int(a)-i,int(b)-1+i)

Buggy submission (verdict: Runtime Error):
s,a,u=open(0);i=s.find(u)<1;print(int(a[0])-i,int(a[2])-1+i)
Problem p02790 (python)

Fixed submission:
a,b=input().split()
print(min(a*int(b),b*int(a)))

Buggy submission (verdict: Runtime Error):
_,a,b=sorted(input())[1:];print(a*int(b))
Problem p02793 (python)

Fixed submission:
from fractions import*
from functools import*
M=10**9+7
_,a=open(0)
*a,=map(int,a.split())
s=reduce(lambda x,y:x//gcd(x,y)*y,a)%M
c=0
for i in a:
    c+=s*pow(i,M-2,M)
    c%=M
print(c)

Buggy submission (verdict: Runtime Error):
from fractions import*
l=lambda x,y=x//gcd(x,y)*y
n,*a=map(int,open(0).read().split())
s=1
for i in a:s=l(s,i)
print(sum(s//i for i in a)%(10**9+7))

Buggy submission (verdict: Runtime Error):
from numpy import*
M=10**9+7
_,a=open(0)
a=int64(a.split())
print(sum(lcm.reduce(a)//a)%M)
Problem p02820 (python)

Fixed submission:
*n,t=open(0).read().split()
n,k,r,s,p=map(int,n)
d={'r':p,'s':r,'p':s}
b=['']*n*2
a=0
for i,c in enumerate(t[:n]):
  if c!=b[i-k]:
    b[i]=c
    a+=d[c]
print(a)

Buggy submission (verdict: Runtime Error):
*t,s=open(0).read().split()
n,k,r,s,p=map(int,t)
d={'r':p,'s':r,'p':s}
b=['']*n*2
a=0
for i,c in enumerate(s[:n]):
  if c!=b[i-k]:
    b[i]=c
    a+=d[c]
print(a)
Problem p02835 (python)

Fixed submission:
print('bwuisnt'[sum(map(int,input().split()))<22::2])

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

Buggy submission (verdict: Runtime Error):
*a,=map(int,open(0))

Buggy submission (verdict: Runtime Error):
a,b=map(int,open(0))
if a+b>21:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a+b>21:
    print('No')
else:
    print('Yes')
Problem p02851 (python)

Fixed submission:
n,k,*a=map(int,open(0).read().split())
a=[0]+a
for i in range(n):a[i+1]=(a[i+1]-1+a[i])%k
d={}
c=0
for i,b in enumerate(a):
  v=d.get(b,0)
  c+=v
  d[b]=v+1
  j=i-k+1
  if j>=0:d[a[j]]=d.get(a[j],0)-1
print(c)

Buggy submission (verdict: Runtime Error):
n,k,*a=map(int,open(0).read().split())
a=[0]+a
for i in range(n):a[i+1]=(a[i+1]-1+a[i])%k
d=[0]*k
c=0
for i,b in enumerate(a):
  c+=d[b]
  d[b]+=1
  if i-k>-2:d[a[i-k+1]]-=1
print(c)
Problem p02863 (python)

Fixed submission:
e=enumerate
(n,t),*g=[list(map(int,t.split()))for t in open(0)]
d=[0]
g.sort()
dp=[]
d=[0]*t
for a,b in g:
  p=d[:]
  for i in range(a,t):
    v=d[i-a]+b
    if v>p[i]:p[i]=v
  dp+=p,
  d=p
a=m=0
for(*_,v),(_,w)in zip(dp[-2::-1],g[::-1]):
  if w>m:m=w
  if v+m>a:a=v+m
print(a)

Buggy submission (verdict: Runtime Error):
from numpy import*
N,T,*L=int64(open(0).read().split())
d=zeros(T*2,int)
for w,v in sorted(zip(*[iter(L)]*2)):d[w:T+w]=maximum(d[w:T+w],d[:T]+v)
print(max(d))
Problem p02891 (python)

Fixed submission:
from itertools import*
s,k=open(0)
k,x=int(k),0
g=[len(list(v))for _,v in groupby(s)]
for c in g:x+=c//2
x*=k
if(s[0]==s[-2])*g[0]%2&g[-2]%2:x+=k//2if-len(s)==~g[0]else k-1
print(x)

Buggy submission (verdict: Runtime Error):
from itertools import*
s,k=open(0)
k=int(k)
g=[len(list(v))for _,v in groupby(s)]
print(sum(c//2for c in g)*k+((s[0]==s[-2])*g[0]%2&g[-2]%2)*(k//2*(-len(s)~g[0])or k-1))
Problem p02948 (python)

Fixed submission:
from collections import*
from heapq import*
n,m,*t=map(int,open(0).read().split())
d=defaultdict(list)
for a,b in zip(t[::2],t[1::2]):d[a].append(b)
q=[]
for i in sorted(d.keys())[::-1]:
    for b in sorted(d[i])[::-1][:m-i+1]:
        if len(q)<=m-i:heappush(q,b)
        elif q and q[0]<b:heappushpop(q,b)
print(sum(q))

Buggy submission (verdict: Runtime Error):
from heapq import*
(N,M),*t=[map(int,s.split())for s in open(0)]
z,*q=[0]*50*M
v=[[]for _ in q]
for a,b in t:v[a-1]+=b,
for i in v[:M]:z-=[heappush(q,-j)for j in i]or heappop(q)
print(z)

Buggy submission (verdict: Runtime Error):
from heapq import*
(N,M),*t=[map(int,s.split())for s in open(0)]
z,*q=[0]*9*M
v=[[]for _ in q]
for a,b in t:v[a-1]+=b,
for i in v[:M]:
 for j in i:heappush(q,-j)
 z-=heappop(q)
print(z)

Buggy submission (verdict: Runtime Error):
from heapq import*
(N,M),*t=[map(int,s.split())for s in open(0)]
q=[0]*M
v=[[]for _ in q]
z=0
for a,b in t:v[a-1]+=[b]*(a<=M)
for i in v:
	for j in i:heappush(q,-j)
	z-=heappop(q)
print(z)

Buggy submission (verdict: Runtime Error):
from collections import*
from heapq import*
n,m,*t=map(int,open(0).read().split())
d=defaultdict(list)
for a,b in zip(t[::2],t[1::2]):d[a].append(b)
q=[]
for i in sorted(d.keys())[::-1]:
    for b in sorted(d[i])[::-1][:m-i+1]:
        if len(q)<=m-i:heappush(q,b)
        else:
            if q[0]<b:heappushpop(q,b)
print(sum(q))

Buggy submission (verdict: Runtime Error):
from heapq import*
n,m,*t=map(int,open(0).read().split())
k=max(t)
d=[[]for _ in range(k+1)]
for a,b in zip(t[::2],t[1::2]):d[a]+=b,
q=[]
for i,b in enumerate(d[::-1]):
    i=k-i
    for b in sorted(b)[::-1][:m-i+1]:
        if len(q)<=m-i:heappush(q,b)
        else:
            if q[0]<b:heappushpop(q,b)
print(sum(q))
Problem p02951 (python)

Fixed submission:
print(max(0,eval('-'+input().replace(' ','+'))))

Buggy submission (verdict: Runtime Error):
print(max(0,eval('-'+input().replace(' ','+')))
Problem p02964 (python)

Fixed submission:
from bisect import*
from collections import*
n,k,*a=map(int,open(0).read().split())
b=defaultdict(list)
for i,v in enumerate(a):b[v]+=i,
s=a[0]
i=c=0
while 1:
  t=b[s]
  m=len(t)
  j=bisect(t,i)
  c+=j==m
  i=t[j%m]+1
  if i==n:break
  s=a[i]
k%=c+1
s=a[0]
i=c=0
while c<k-1:
  t=b[s]
  m=len(t)
  j=bisect(t,i)
  c+=j==m
  i=t[j%m]+1
  s=a[i]
r=[]
while 1:
  t=b[s]
  m=len(t)
  j=bisect(t,i)
  if j==m:
    r+=s,
    i+=1
  else:
    i=t[j]+1
  if i==n:
    break
  s=a[i]
print(*r)

Buggy submission (verdict: Runtime Error):
n,k,*a=map(int,open(0).read().split())
l,r,*b=[[]for _ in range(10**6)]
for i,v in enumerate(a):
  b[v]+=i,
  l+=len(b[v]),
s=a[0]
i=c=0
while 1:
  j=l[i]%len(b[s])
  if(c>k-2)>j:
    r+=s,
    i+=1
  else:i=-~b[s][j]%n
  c+=j<1
  if i<1:
    if c>k-2:break
    k%=c+1
    c=0
  s=a[i]
print(*r)

Buggy submission (verdict: Runtime Error):
from bisect import*
from collections import*
n,k,*a=map(int,open(0).read().split())
b=defaultdict(list)
for i,v in enumerate(a):b[v]+=i,
s=a[0]
i=c=0
while 1:
  t=b[s]
  m=len(t)
  j=bisect(t,i)
  c+=j==m
  i=t[j%m]+1
  if i==n:break
  s=a[i]
k%=c+1
"""
s=[]
for i in a*k:
  if i in s:s=s[:s.index(i)]
  else:s+=i,
print(*s)
"""
a*k

Buggy submission (verdict: Runtime Error):
from bisect import*
n,k,*a=map(int,open(0).read().split())
b=[[]for _ in range(max(a)+1)]
for i,v in enumerate(a):b[v]+=i,
s=a[0]
i=c=0
while 1:
  t=b[s]
  m=len(t)
  j=bisect(t,i)
  c+=j==m
  i=t[j%m]+1
  if i==n:break
  s=a[i]
k%=c+1
s=[]
for i in a*k:
  if i in s:s=s[:s.index(i)]
  else:s+=i,
print(*s)

Buggy submission (verdict: Runtime Error):
from bisect import*
n,k,*a=map(int,open(0).read().split())
b=[[]for _ in range(n+1)]
for i,v in enumerate(a):b[v]+=i,
s=a[0]
i=c=0
while 1:
  t=b[s]
  m=len(t)
  j=bisect(t,i)
  c+=j==m
  i=t[j%m]+1
  if i==n:break
  s=a[i]
k%=c+1
s=[]
for i in a*k:
  if i in s:s=s[:s.index(i)]
  else:s+=i,
print(*s)
Problem p02990 (python)

Fixed submission:
class F:
    def __init__(self,n,mod):
        self.mod=mod
        self.f=[1]
        for i in range(1,n+1):
            self.f.append(self.f[-1]*i%mod)
        self.i=[pow(self.f[-1],mod-2,mod)]
        for i in range(1,n+1)[::-1]:
            self.i.append(self.i[-1]*i%mod)
        self.i.reverse()
    def factorial(self,i):
        return self.f[i]
    def ifactorial(self,i):
        return self.i[i]
    def comb(self,n,k):
        return 0 if k>n else self.f[n]*self.i[n-k]*self.i[k]%self.mod
n,k=map(int,input().split())
M=10**9+7
c=F(n,M).comb
for i in range(k):
    print(c(n-k+1,i+1)*c(k-1,i)%M)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
p=n-k+1
for i in range(k):print(p%(10**9+7));p=p*(k-i)*(n-k+1-i)//i//-~i
Problem p03017 (python)

Fixed submission:
n,a,b,c,d=map(int,input().split())
s=input()
if'##'in s[a:c]or'##'in s[b:d]or d<c and not'...'in s[b-2:d+1]:
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
n,a,b,c,d=map(int,input().split());s=input();t=[b-2:d+1];print('YNeos'[not'...'*(d<c)in t or'##'in s[a:c]+t::2])
Problem p03038 (python)

Fixed submission:
n,m,*t=map(int,open(0).read().split())
a=sorted(t[:n])[::-1]
m=0
for c,b in sorted(zip(t[n+1::2],t[n::2]))[::-1]:
 while a and b and c>a[-1]:m+=c;b-=1;a.pop()
print(m+sum(a))

Buggy submission (verdict: Runtime Error):
n,m,*t=map(int,open(0).read().split())
a=sorted(t[:n])[::-1]
m=0
for c,b in sorted(zip(t[n+1::2],t[n::2]))[::-1]:
 while a*b and c>a[-1]:m+=c;b-=1;a.pop()
print(m+sum(a))
Problem p03042 (python)

Fixed submission:
s=input();a,b=int(s[:2]),int(s[2:]);print(['NA','MMYY','YYMM','AMBIGUOUS'][(0<a<13)-(0<b<13)*2])

Buggy submission (verdict: Runtime Error):
s=input();print['NA','MMYY','YYMM','AMBIGUOUS'][(99<s<1300)-(0<s%100<13)*2]
Problem p03055 (python)

Fixed submission:
from collections import*
def s(s):
  f=[1]*-~n
  f[s]=0
  q=deque([(s,0)])
  while q:
    t,c=q.popleft()
    for v in e[t]:
      if f[v]:
        f[v]=0
        q.append((v,c+1))
  return t,c
n,*t=map(int,open(0).read().split())
e=[[]for _ in range(n+1)]
for a,b in zip(t[::2],t[1::2]):
  e[a].append(b)
  e[b].append(a)
print('SFeicrosntd'[s(s(1)[0])[1]%3!=1::2])

Buggy submission (verdict: Runtime Error):
from scipy.sparse import*;n,*t=map(int,open(0).read().split());print('SFeicrosntd'[csgraph.dijkstra(csr_matrix(([1]*~-n,(t[::2],t[1::2])),[n+1]*2),0)[1:,1:].max()%3!=1::2])

Buggy submission (verdict: Runtime Error):
from collections import*
def s():
 global a,b;f,q=[1]*-~n,deque([(a,0)])
 while q:
  a,b=q.popleft()
  for v in e[a]:q+=[(v,b+1)]*f[v];f[v]=0
n,*t=map(int,open(0).read().split())
e=[[]for _ in[0]*-~n]
for a,b in zip(t[::2],t[1::2]):e[a]+=b,;e[b]+=a,
s(),s()
print('SFeicrosntd'[b%3!=1::2])
Problem p03108 (python)

Fixed submission:
class UnionFind:
  def __init__(self,n):
    *self.table,=range(n)
    self.rank=[1]*n
  def root(self,x):
    if self.table[x]==x:
      return x
    else:
      self.table[x]=self.root(self.table[x])
      return self.table[x]
  def unite(self,x,y):
    x=self.root(x)
    y=self.root(y)
    if x!=y:
      if self.rank[x]<self.rank[y]:
        x,y=y,x
      self.rank[x]+=self.rank[y]
      self.table[y]=x
  def same(self,x,y):
    return self.root(x)==self.root(y)
  def size(self,x):
    return self.rank[self.root(x)]
(n,m),_,*e=[map(int,t.split())for t in open(0).readlines()]
u=UnionFind(n)
a=[n*~-n//2]
for x,y in e[::-1]:
  x,y=x-1,y-1
  t=a[-1]
  if not u.same(x,y):
    t-=u.size(x)*u.size(y)
  a.append(t)
  u.unite(x,y)
print(*a[::-1],sep='\n')

Buggy submission (verdict: Runtime Error):
r=lambda x:x if u[x]<0else r(u[x])
(n,m),_,*e=[map(int,t.split())for t in open(0).readlines()]
u=[-1]*-~n
a=[n*~-n//2]
for x,y in e[::-1]:
 t=a[-1];x,y=r(x),r(y)
 if x!=y:t-=u[x]*u[y];u[x]+=u[y];u[y]=x
 a.append(t)
print(*a[::-1],sep='\n')
Problem p03221 (python)

Fixed submission:
I=lambda:map(int,input().split())
n,m=I()
l=[[]for _ in range(n+1)]
for i in range(m):
  p,y=I()
  l[p].append([y,i])
a=[]
for p in range(1,n+1):
  l[p].sort()
  for i,t in enumerate(l[p]):
    a.append([t[1],'%06d'%p+'%06d'%-~i])
a.sort()
for t in a:
  print(t[1])

Buggy submission (verdict: Runtime Error):
I=lambda:list(map(int,input().split()))[::-1];m,n=I();l=[I()+[i]for i in range(m)];c=[0]*-~n;a=[0]*m
for y,p,i in sorted(l):c[p]+=1;a[i]='%06d'%p+'%06d'%c[p]
print('\n'.join(t))

Buggy submission (verdict: Runtime Error):
I=lambda:list(map(int,input().split()));n,m=I();l=[I()+[i]for i in range(M)];c=[0]*-~N;a=[0]*M
for p,y,i in sorted(l,key=lambda x:x[1]):c[p]+=1;a[i]='%06d'%p+'%06d'%c[p]
for t in a:print(t)
Problem p03242 (python)

Fixed submission:
print(''.join(map(lambda x:{'1':'9','9':'1'}[x],input())))

Buggy submission (verdict: Runtime Error):
print(''.join(map(lambda x:{'1':'9','9':'1'}[x],input().split())))
Problem p03252 (python)

Fixed submission:
s,t=[0]*26,[0]*26
for a,b in zip(input(),input()):
  s[ord(a)-ord('a')]+=1
  t[ord(b)-ord('a')]+=1
u,v=[],[]
for a,b in zip(s,t):
  if a!=b:
    u.append(a)
    v.append(b)
print('YNeos'[sorted(u)!=sorted(v)::2])

Buggy submission (verdict: Runtime Error):
from collections import*;C=Counter;print('YNeos'[eval('!=C(C(input()).values())'*2[2:])::2])
Problem p03286 (python)

Fixed submission:
n=int(input())
s=''
while n!=0:
  s=str(n%2)+s
  n=-(n//2)
print(s*(s!='')or 0)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=''
while n!=0:
  s=str(n%2)+s
  n=-(n//2)
print(s*(s!='')else 0)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=''
while n!=0:
  s=str(n%2)+s
  n=-(n//2)
print(s*(if s)else 0)
Problem p03329 (python)

Fixed submission:
def s(n,c):
  if n<6:return c+n
  a=b=1
  while a*6<=n:a*=6
  while b*9<=n:b*=9
  return min(s(n-a,c+1),s(n-b,c+1))
print(s(int(input()),0))

Buggy submission (verdict: Runtime Error):
s=lambda a,b:a*(a<b)or s(a//b,b)+a%b;n=int(input());print(min(s(i,6)+s(n-i,9)for i in range(n+1)))

Buggy submission (verdict: Runtime Error):
def s(a,b):return[s(a//b,b)+a%b,a][a<b]
n=int(input());print(min(s(i,6)+s(n-i,9)for i in range(n+1)))

Buggy submission (verdict: Runtime Error):
def s(n,p):
  while n>0:yield n%p;n//=p
c=lambda*a:sum(s(*a));n=int(input())print(min(c(i,6)+c(n-i,9)for i in range(n+1)))

Buggy submission (verdict: Runtime Error):
def s(n,p):
  while n>0:yield n%p;n//=p
c=lambda*a:sum(s(*a))
print(min(c(i,6)+c(n-i,9)for i in range(int(input())+1)))

Buggy submission (verdict: Runtime Error):
def s(n,p):
  while n>0:yield n%p;n//=p
c=lambda*a:sum(s(*a));print(min(c(i,6)+c(n-i,9)for i in range(int(input())+1)))
Problem p03332 (python)

Fixed submission:
n,a,b,k=map(int,input().split())
m=998244353
I=[0]*n
for i in range(n):
  I[i]=pow(i+1,m-2,m)
c=[0]*(n+1)
c[0]=1
for i in range(1,n+1):
  c[i]=(c[i-1]*(n-i+1)*I[i-1])%m
q=0
for i in range(n+1):
  j=(k-i*a)//b
  if (k-i*a)%b or j<0 or j>n:continue
  q=(q+c[i]*c[j])%m 
print(q%m)

Buggy submission (verdict: Runtime Error):
n,a,b,k=map(int,input().split())
m=998244353
I=[0]*n
for i in range(n):
  I[i]=pow(i+1,m-2,m)
c=[0]*(n+1)
c[0]=1
for i in range(1,n+1):
  c[i]=(c[i-1]*(n-i+1)*I[i-1])%m
q=0
for i in range(0,n+1):
  j=k-i*a
  if j<0 or j%b:continue
  j//=b
  q=(q+c[i]*c[j])%m
print(q%m)

Buggy submission (verdict: Runtime Error):
import math
from functools import lru_cache
@lru_cache(maxsize=None)
def p(n,r):
  return math.factorial(n)//math.factorial(n-r)
@lru_cache(maxsize=None)
def c(n,r):
  return p(n,r)//math.factorial(r)
n,a,b,k=map(int,input().split())
m=998244353
q=0
for i in range(0,n+1):
  j=k-i*a
  if j<0 or j%b:continue
  j//=b
  q=(q+c(n,i)*c(n,j))%m
print(q%m)
Problem p03652 (python)

Fixed submission:
from numpy import*
a=loadtxt(open(0),'i',skiprows=1,ndmin=2)
n=x=len(a)
while a.any():
  t=bincount(a[:,0])
  x,a=min(x,max(t)),reshape(a[a!=argmax(t)],(n,-1))
print(x)

Buggy submission (verdict: Runtime Error):
from numpy import*
a=loadtxt(open(0),'i',skiprows=1)
n=x=len(a)
while a.any():
  t=bincount(a[:,0])
  x,a=min(x,max(t)),reshape(a[a!=argmax(t)],(n,-1))
print(x)
Problem p03724 (python)

Fixed submission:
l=[0]*2**17
for i in open(0).read().split()[2:]:l[int(i)]+=1
print('YNEOS'[any(i%2for i in l)::2])

Buggy submission (verdict: Runtime Error):
l=[0]*2**14
for i in open(0).read().split()[2:]:l[int(i)]+=1
print('YNEOS'[any(i%2for i in l)::2])
Problem p03725 (python)

Fixed submission:
from collections import deque
h, w, k = map(int, input().split())
maze = [input() for _ in range(h)]
visited = [[-1]*w for j in range(h)]
for i in range(h):
    if 'S' in maze[i]:
        sy, sx = i, maze[i].index('S')
queue = deque([[sy, sx]])
visited[sy][sx] = 0
r = 10**18
while queue:
    y, x = queue.popleft()
    r = min(r, y, x, h-1-y, w-1-x)
    if visited[y][x] == k: continue
    for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
        new_y, new_x = y+i, x+j
        if new_y < 0 or new_y >= h: continue
        if new_x < 0 or new_x >= w: continue
        if maze[new_y][new_x] == '.' and visited[new_y][new_x] == -1:
            visited[new_y][new_x] = visited[y][x] + 1
            queue.append([new_y, new_x])
print(1 -(-r // k))

Buggy submission (verdict: Runtime Error):
from collections import*
H,*A=open(0)
H,W,K=map(int,H.split())
*A,=map(list,A)
for i,a in enumerate(A):
	if'S'in a:j=a.index('S');Q=deque([(0,i,j)])
d=1e9
while Q:
	c,i,j=Q.popleft();d=min(d,i,j,H-i-1,W-j-1)
	if c<K:
		for h,w in((i+1,j),(i,j+1),(i-1,j),(i,j-1)):
			if(H>h>-1<w<W)*'.'==A[h][w]:A[h][w]=0;Q+=(c+1,h,w),
print(1--d//K)

Buggy submission (verdict: Runtime Error):
from collections import deque;h,w,k=map(int,input().split());m=[input()for _ in[0]*h];v=[[-1]*w for _ in[0]*h];r=9**20
for i in range(h):
 if'S'in m[i]:j=m[i].index('S');q=deque([[i,j]])v[i][j]=0
while q:
 y,x=q.popleft()
 r=min(r,y,x,h-1-y,w-1-x)
 if v[y][x]==k:continue
 for i,j in([1,0],[-1,0],[0,1],[0,-1]):
  t,u=y+i,x+j
  if t>=0and t<h and u>=0and u<w and m[t][u]=='.'and v[t][u]<0:v[t][u]=v[y][x]+1;q.append([t,u])
print(1-(-r//k))
Problem p03822 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
e=enumerate
def dfs(v):
  d=sorted(map(dfs,t[v]))
  l=len(d)
  return max([0]+[l-i+d for i,d in e(d)])
n,*a=map(int,open(0))
t=[[]for _ in[0]+a]
for i,v in e(a,1):t[v-1]+=i,
print(dfs(0))

Buggy submission (verdict: Runtime Error):
def dfs(v):
  d=sorted(map(dfs,t[v]))
  l=len(d)
  return max([0]+[l-i+d for i,d in e(d)])
e=enumerate
n,*a=map(int,open(0))
t=[[]for _ in[0]+a]
for i,v in e(a,1):t[v-1]+=i,
print(dfs(0))
Problem p03835 (python)

Fixed submission:
k,s=map(int,input().split());r=k+1;print(sum(k>=s-I//r-I%r>=0for I in range(r*r)))

Buggy submission (verdict: Runtime Error):
k,s=map(int,input().split());k+=1;print(sum(k>=s-x//k-y%k>=0for I in range(k**2)))
Problem p03839 (python)

Fixed submission:
n,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
s=[0]
p=[0]
for i in range(1,n+1):
  s.append(s[i-1]+a[i])
  p.append(p[i-1]+max(0,a[i]))
ans=0
for i in range(1,n-k+2):
  t=max(0,s[i+k-1]-s[i-1])
  t+=p[i-1]+p[n]-p[i+k-1]
  ans=max(ans,t)
print(ans)

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

Fixed submission:
import itertools

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

c = [i for i in range(2, n + 1)]
b = []
for x in itertools.permutations(c):
  b.append([1] + list(x))
  
cnt = 0
for x in b:
  exist = True
  for i in range(n-1):
    if not sorted(x[i:i+2]) in a:
      exist = False
      break
  if exist:
    cnt += 1

print(cnt)

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

c = [i for i in range(2, n + 1)]
b = []
for x in itertools.permutations(c):
  b.append([1] + list(x))
  
cnt = 0
for x in b:
  exist = True
  for i in range(n-1):
    if not sorted(x[i:i+2]) in a:
      exist = False
      break
  if exist:
    cnt += 1

print(cnt)
Problem p02633 (python)

Fixed submission:
import math
n=int(input())
if 360%n==0:
    print(360//n)
else:
    r=360*n//math.gcd(360,n)
    r//=n
    print(r)

Buggy submission (verdict: Runtime Error):
n=int(input())
r=math.ceil(Fraction(360,n))
print(r)
Problem p02659 (python)

Fixed submission:
from fractions import Fraction
n,k=map(str,input().split())
a=int(n)
b=int(k[len(k)-2:])
c=int(k[:len(k)-3])
ans=a*c
t=Fraction(a*b,100)
ans+=int(t)
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(float,input().split())
p=n*k
p=math.floor(p)
print(p)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
p=n*k
p=p//1
print(p)