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

Fixed submission:
# -*- coding: utf-8 -*-
from sys import stdin
import math

in_strings = lambda: stdin.readline()[:-1] # s = in_strings()
in_int = lambda: int(stdin.readline()) # N = in_int()
in_intlist = lambda: list(map(int, stdin.readline().split())) # List = in_intlist()

N, A, B, K = in_intlist()
NUM = 998244353

# 逆元
Inv = [0 for _ in range(N)]
for i in range(N):
    Inv[i] = pow(i+1, NUM-2, NUM)

# Combination
Comb = [0 for _ in range(N+1)]
Comb[0] = 1
for i in range(1, N+1):
    Comb[i] = (Comb[i-1] * (N-i+1) * Inv[i-1]) % NUM


ans = 0
for i in range(N+1):
    if ((K - i*A) % B == 0) and (0 <= (K - i*A) // B <= N):
        ans = (ans + Comb[i]*Comb[(K - i*A) // B]) % NUM 

print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from sys import stdin
import math

in_strings = lambda: stdin.readline()[:-1] # s = in_strings()
in_int = lambda: int(stdin.readline()) # N = in_int()
in_intlist = lambda: list(map(int, stdin.readline().split())) # List = in_intlist()

N, A, B, K = in_intlist()
NUM = 998244353

# 逆元
Inv = [0 for _ in range(N)]
for i in range(N):
    Inv[i] = pow(i+1, NUM-2, NUM)

# Combination
Comb = [0 for _ in range(N+1)]
Comb[0] = 1
for i in range(1, N+1):
    Comb[i] = (Comb[i-1] * (N-i+1) * Inv[i-1]) % NUM


ans = 0
for i in range(max(0, (K-N*B)//A), min(N+1, K//A + 1)):
    if (K - i*A) % B == 0:
        ans = (ans + Comb[i]*Comb[(K - i*A) // B]) % NUM 

print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from sys import stdin
import math

in_strings = lambda: stdin.readline()[:-1] # s = in_strings()
in_int = lambda: int(stdin.readline()) # N = in_int()
in_intlist = lambda: list(map(int, stdin.readline().split())) # List = in_intlist()

N, A, B, K = in_intlist()
NUM = 998244353

# 逆元
Inv = [0 for _ in range(N)]
for i in range(N):
    Inv[i] = pow(i+1, NUM-2, NUM)

# Combination
Comb = [0 for _ in range(N+1)]
Comb[0] = 1
for i in range(1, N+1):
    Comb[i] = (Comb[i-1] * (N-i+1) * Inv[i-1]) % NUM


ans = 0
for i in range(N+1):
    if ((K - i*A) % B == 0) and ((K - i*A) // B <= N):
        ans = (ans + Comb[i]*Comb[(K - i*A) // B]) % NUM 

print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from sys import stdin
import math

in_strings = lambda: stdin.readline()[:-1] # s = in_strings()
in_int = lambda: int(stdin.readline()) # N = in_int()
in_intlist = lambda: list(map(int, stdin.readline().split())) # List = in_intlist()

N, A, B, K = in_intlist()
NUM = 998244353

def Comb(n, k):
    return math.factorial(n) // (math.factorial(n-k) * math.factorial(k)) 

ans = 0
for i in range(N+1):
    if ((K - i*A) % B == 0) and ((K - i*A) // B <= N):
        ans = (ans + Comb(N, i)*Comb(N, (K - i*A) // B)) % NUM 

print(ans)
Problem p02699 (python)

Fixed submission:
s,w=map(int,input().split())
if w<s:
    print("safe")
else:
    print("unsafe")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000000)
s=input()
n=len(s)
def mod10(x):
    p=x//10000000
    q=x-10000000*p
    if p==0:
        return (10**q)%2019
    return ((10**q)*mod10(p))%2019

def T(i):
    if i==n-1:
        return int(s[n-1])
    return T(i+1)+10**(n-1-i)*int(s[i])
dict={}
def modi(i,dict):
    if i in dict.keys():
        return dict[i]
    else:
        if i==n-1:
            dict[i]=int(s[i])
            return int(s[i])
        else:
           # c=modi(i+1,dict)+(10**(n-1-i)*int(s[i]))
            c=modi(i+1,dict)+(mod10(n-1-i)*int(s[i]))
            c=c%2019
            dict[i]=c
            return c

modnum={}
for i in range(n):
    #print(T(i))
    if int(s[i])==0:
        continue
    x=modi(i,dict)
 #   print(T(i),x)
    if x not in modnum.keys():
        modnum[x]=1
    else:
        modnum[x]+=1
sum=0
for md in modnum.keys():
    a=modnum[md]
    if md==0:
        sum+=a
        sum+=-(a*(a-1)//2)
   # print(a*(a-1)//2)
    sum+=a*(a-1)//2
#print(modnum)
print(sum)
Problem p02723 (python)

Fixed submission:
s=input()

x=1
if s[2]!=s[3]:
    x=0
    
if s[4]!=s[5]:
    x=0
    
        
if x==1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import sys
import queue
def main():
    input=sys.stdin.readline
    n,x,y=map(int,input().split())
    edge=[]
    for i in range(int(n)):
        tmp=[0 if i==j else 1 if abs(i-j)==1 else -1 for j in range(n)]
        edge.append(tmp)
    edge[x-1][y-1]=1
    edge[y-1][x-1]=1
    step=[0]*n#ある歩数の点の選び方をカウントする
    def bfs(start,graph,step):
        kyori={}#スタートからある点までの距離をある点をキーとして入れる
        que_check=[0]*n#queueに入ったかを記録する
        Tovis=queue.Queue()#探索待ちの点を入れるキュー
        Tovis.put(start)
        que_check[start]=1
        kyori[start]=0        
        while Tovis.empty()==False:            
            nex=Tovis.get()            
            for v in range(n):                
                tmp=graph[nex][v]
                if tmp!=-1:                    
                    if que_check[v]==1:
                        continue
                    Tovis.put(v)
                    que_check[v]=1
                    res=kyori[nex]+1
                    kyori[v]=res#点ｖまでの距離はその前に通った点までの距離+1
                    step[res]+=0.5#i->j j->iの二回数えてしまうので
    for i in range(n):
        bfs(i,edge,step)
    for i in range(1,len(step)):
        print(int(step[i]))
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
n,x,y=map(int,input().split())
edge=[]
for i in range(int(n)):
    tmp=[0 if i==j else 1 if abs(i-j)==1 else -1 for j in range(n)]
    edge.append(tmp)
edge[x-1][y-1]=1
edge[y-1][x-1]=1
step=[0 for i in range(n)]#ある歩数の点の選び方をカウントする
def bfs(start,graph,step):
    kyori={}#スタートからある点までの距離をある点をキーとして入れる
    num=0
    Tovis=[start]
    kyori[start]=0
    visited=[]
    while Tovis:
        nex=Tovis.pop(0)
        visited.append(nex)
        for v in range(len(graph[nex])):
            tmp=graph[nex][v]
            if tmp!=-1:
                if v in visited:
                    continue
                if  v in Tovis:
                    continue
                Tovis.append(v)
                kyori[v]=kyori[nex]+1#点ｖまでの距離はその前に通った点までの距離+1
                step[kyori[v]]+=0.5#i->j j->iの二回数えてしまうので
for i in range(n):
    bfs(i,edge,step)
for i in range(1,len(step)):
    print(int(st
Problem p03804 (python)

Fixed submission:
import sys
n, m = map(int, input().split())
image = []
temp = []
match = False
for i in range(n):
  image.append(input())
for i in range(m):
  temp.append(input())
for i in range(n):
  for j in range(n - m + 1):
    if (temp[0] == image[i][j : j + m]):
      match = True
      for k in range(1, m):
        if (i + k >= n):
          match = False
          break
        elif (temp[k] != image[i + k][j : j + m]):
          match = False
          break
      if (match == True):
        print('Yes')
        sys.exit()
print('No')

Buggy submission (verdict: Runtime Error):
import sys
n, m = map(int, input().split())
image = []
temp = []
match = False
for i in range(n):
  image.append(input())
for i in range(m):
  temp.append(input())
for i in range(n):
  for j in range(n - m + 1):
    if (temp[0] == image[i][j : j + m]):
      match = True
      for k in range(1, m):
        if ((temp[k] != image[i + k][j : j + m]) | (i + k >= n)):
          match = False
          break
      if (match == True):
        print('Yes')
        sys.exit()
print('No')
Problem p02863 (python)

Fixed submission:
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a)]
c.sort()
DP=[[0 for j in range(b+1)]for i in range(a)]
for i in range(c[0][0],b+1):
  DP[0][i]+=c[0][1]
for i in range(1,a):
  for j in range(b):
    if j<c[i][0]:
      DP[i][j]=DP[i-1][j]
    else:
      DP[i][j]=max(DP[i-1][j-c[i][0]]+c[i][1],DP[i-1][j])
  DP[i][b]=max(DP[i-1][b-1]+c[i][1],DP[i-1][b])
print(max(DP[-1]))

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a)]
c.sort()
DP=[[0 for j in range(b+1)]for i in range(a)]
for i in range(c[0][0],b+1):
  DP[0][i]+=c[0][1]
for i in range(1,a):
  for j in range(c[i][0]):
    DP[i][j]=DP[i-1][j]
  for j in range(c[i][0],b):
    DP[i][j]=max(DP[i-1][j-c[i][0]]+c[i][1],DP[i-1][j])
  DP[i][b]=max(DP[i-1][b-1]+c[i][1],DP[i-1][b])
print(max(DP[-1]))
Problem p02925 (python)

Fixed submission:
from collections import deque
import sys
input=sys.stdin.readline
def main():
  a=int(input())
  b=[[]for i in range(a)]
  for i in range(a):
    b[i]=deque(list(map(int,input().split())))
  c=[[]for i in range(a)]
  ans=0
  d=[i for i in range(a)]
  while d:
    nextd=[]
    f=set()
    ans+=1
    T=0
    for i in d:
      if i not in f and len(b[i])>0:
        e=b[i][0]-1
        if e in c[i]:
          c[i].pop(c[i].index(e))
          T=1
          b[e].popleft()
          b[i].popleft()
          if len(b[i])>0:
            nextd.append(i)
          if len(b[e])>0:
            nextd.append(e)
          f|={i,e}
        else:
          c[e].append(i)
    if T==0:
      print(-1)
      exit()
    d=nextd
      
      
  print(ans)  
if __name__ == '__main__':  
  main()

Buggy submission (verdict: Runtime Error):
from collections import deque
import sys
input=sys.stdin.readline
def main():
  a=int(input())
  b=[[]for i in range(a)]
  for i in range(a):
    b[i]=deque(list(map(int,input().split())))
  c=[[]for i in range(a)]
  ans=0
  d=[0 for i in range(a)]
  while sum(len(v) for v in b)!=0:
    f=[0 for i in range(a)]
    ans+=1
    T=0
    for i in range(a):
      if d[i]==0 and f[i]==0 or len(b[i])>0:
        e=b[i][0]-1
        if e in c[i]:
          c[i].pop(c[i].index(e))
          T=1
          b[e].popleft()
          b[i].popleft()
          d[i]=0
          d[e]=0
          f[i]=1
          f[e]=1
        else:
          c[e].append(i)
          d[i]=1
    if T==0:
      print(-1)
      exit()
      
      
  print(ans)  
if __name__ == '__main__':  
  main()
Problem p02933 (python)

Fixed submission:
a=int(input())
b=input()
if a>=3200:
  print(b)
else:
  print("red")

Buggy submission (verdict: Runtime Error):
from collections import deque
import sys
def main():
  a,b=map(int,sys.stdin.readline().split())
  e=[[]for i in range(a)]

  for i in range(a-1):
    c1,c2=map(int,sys.stdin.readline().split())
    e[c1-1].append(c2-1)
    e[c2-1].append(c1-1)

  g=[[]for i in range(a)]
  f=deque([(0,-1)])
  ans=[0 for _ in range(a)]
  for i in range(b):
    ten,p=map(int,input().split())
    ans[ten-1]+=p
  i=0
  while len(f)!=0:
    i,fr=f.pop()
    for j in e[i]:
      if j==fr:
        continue
      else:
        ans[j]+=ans[i]
        f.append((j,i)) 
  print(*ans)
if __name__ == '__main__':  
  main()
Problem p02935 (python)

Fixed submission:
a=int(input())
b=list(map(int,input().split()))
b.sort()
c=b[0]

for i in range(1,a):
  c=(c+b[i])/2
  
print(c)

Buggy submission (verdict: Runtime Error):
a=int(input())
b=map(int,input().split())
b.sort()
c=b[0]

for i in range(1,a):
  c=(c+b[i])/2
  
print(c)
Problem p02948 (python)

Fixed submission:
import heapq
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a)]
c.sort()
d=[[0]for i in range(b)]
sum=0
for i,j in c:
  if i<=b:
    d[i-1].append(j)
e=[]

for i in d:
  for j in i:
    heapq.heappush(e,-j)
  sum-=heapq.heappop(e)
      
    
  
print(sum)

Buggy submission (verdict: Runtime Error):
a=int(input())
b=[sorted(input()) for j in range(a)]
c=[[0for i in range(26)] for j in range(a)]
for i in range(a):
  for j in range(10):
    c[i][ord(b[i][j])-97]+=1
sum=0
d=1
c.sort()
for i in range(a-1):
  if c[i]==c[i+1]:
    d+=1
  else:
    sum+=d*(d-1)//2
    d=1
  if i==a-2:
    sum+=d*(d-1)//2
    
print(sum)

Buggy submission (verdict: Runtime Error):
a=int(input())
b=[sorted(input()) for j in range(a)]
c=[[0for i in range(26)] for j in range(a)]
for i in range(a):
  for j in range(10):
    c[i][ord(b[i][j])-97]+=1
sum=0
d=1
c.sort()
print(c)
for i in range(a-1):
  if c[i]==c[i+1]:
    d+=1
  else:
    sum+=d*(d-1)//2
    d=1
  if i==a-2:
    sum+=d*(d-1)//2
    
print(sum)
Problem p02990 (python)

Fixed submission:
import math
a,b=map(int,input().split())
for i in range(1,b+1):
  if a-b+1<i:
    print(0)
  else:
    c=math.factorial(a-b+1)//(math.factorial(i)*math.factorial(a-b+1-i))
    d=math.factorial(b-1)//(math.factorial(i-1)*math.factorial(b-i))
    print((c*d)%1000000007)

Buggy submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
for i in range(1,b+1):
  c=math.factorial(a-b+1)//(math.factorial(i)*math.factorial(a-b+1-i))
  d=math.factorial(b-1)//(math.factorial(i-1)*math.factorial(b-i))
  print((c*d)%1000000007)
Problem p03041 (python)

Fixed submission:
N , K = [int(n) for n in input().split()]
S = input()
print(S[:K-1]+S[K-1].lower()+S[K:])

Buggy submission (verdict: Runtime Error):
N , K = [int(n) for n in input().split()]
S = input()
print(S[:K]+S[K].lower()+S[K+1:])

Buggy submission (verdict: Runtime Error):
N , K = [int(n) for n in input().split()]
S = input()
print(S[:K]+S[k].lower()+S[K:])
Problem p03072 (python)

Fixed submission:
N = int(input())
H = [int(n) for n in input().split()]
ans = 0
for i in range(1, N+1):
  t = max(H[:i])
  if t <= H[i-1]:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
H = [int(n) for n in input().split()]
ans = 0
for i in range(1, N+1):
  t = max(H[:i])
  if t <= H[i]:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
H = [int(n) for n in input().split()]
ans = 0
for i in range(N):
  t = max(H[:i])
  if t <= H[i]:
    ans += 1
print(ans)
Problem p02689 (python)

Fixed submission:
N,M=map(int,input().split())
h=list(map(int,input().split()))
t=[0]*N
for i in range(M):
    A,B=map(int,input().split())
    t[A-1] = max(t[A-1], h[B-1])
    t[B-1] = max(t[B-1], h[A-1])

ct=0
for j in range(N):
    if h[j]>t[j]:
        ct+=1
print(ct)

Buggy submission (verdict: Runtime Error):

N,M=map(int,input().split())
h=list(map(int,input().split()))
t=[0]*N
for i in range(M):
    A,B=map(int,input().split())
    t[A-1] = max(t[A-1], H[B-1])
    t[B-1] = max(t[B-1], H[A-1])

ct=0
for j in range(N):
    if H[j]>[j]:
        ct+=1
print(ct)
Problem p02712 (python)

Fixed submission:
N=int(input())
cal=0
for i in range(1,N+1):
    if i%3==0 or i%5==0 or i%15==0:
        continue
    cal+=i

print(cal)

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

for i in range(1,N+1):
    if i%3==0 or i%5==0 or i%15==0:
        continue
        cal+=i

print(cal)
Problem p02753 (python)

Fixed submission:
s=input()
if s[0]==s[1] and s[1]==s[2]:
  print("No")
  
else :
  print("Yes")

Buggy submission (verdict: Runtime Error):
s=input()
if s[0]=s[1] and s[1]==s[2]:
  print("Yes")
  
else :
  print("No")

Buggy submission (verdict: Runtime Error):
s=input()

if s[0]!==s[1] or s[1]==s[2]:
  print("Yes")
  
else :
  print("No")

Buggy submission (verdict: Runtime Error):
s=input()

for i in range(0,1):
    if s[i]!=s[i+1]:
        X=Yse
        break
    else :
        X=No

print(X)

Buggy submission (verdict: Runtime Error):
s=input()

for i in range(0,1):
    if s[i]!=s[i+1]:
        X=Yes
        break
    else :
        X=No

print(X)

Buggy submission (verdict: Runtime Error):
s=input()

for i in range(0,2):
    if s[i]!=s[i+1]:
        X=Yes
        break
    else :
        X=No

print(X)

Buggy submission (verdict: Runtime Error):
s=input()

for i in range(3):
  if s[i]==s[i+1]:
    print("Yes")
  else :
    print("No")
Problem p02754 (python)

Fixed submission:
N,b,r=map(int,input().split())
ball,x,y=0,0,0
ans=0

ball=b+r
x=N%ball
y=N//ball

ans+=y*b

if x>b:
    ans+=b
else:
    ans+=x


print(ans)

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input(),split())
ans=N//(A+B)*A
r=N%(A+B)
ans+=min(r,A)

print(ans)

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input(),split())
ans=N/(A+B)
r=N%(A+B)
ans+=min(r,A)

print(ans)
Problem p02990 (python)

Fixed submission:
import math
N, K = list(map(int, input().split()))

def combo(n, k):
    x = math.factorial(n)//(math.factorial(k)*math.factorial(n-k))
    return x

for i in range(1,K+1):
    if N-K+1 < i or K-1 < i-1:
        print(0)
    else:
        k = combo(N-K+1,i) * combo(K-1,i-1)
        ans = k%(10**9+7)
        print("%d" %(ans))

Buggy submission (verdict: Runtime Error):
import math
N, K = list(map(int, input().split()))

def combo(n, k):
    x = math.factorial(n)//(math.factorial(k)*math.factorial(n-k))
    return x

for i in range(1,K+1):
    if N-K+1 - i < 0 or K-1 < i-1:
        print(0)
    else:
        k = combo(N-K+1,i) * combo(K-1,i-1)
        ans = k%(math.pow(10,9)+7)
        print("%d" %(ans))

Buggy submission (verdict: Runtime Error):
import math
N, K = list(map(int, input().split()))

def combo(n, k):
    x = math.factorial(n)//(math.factorial(k)*math.factorial(n-k))
    return x

if N == K:
    print(1)
else:
    for i in range(1,K+1):
        k = combo(N-K+1,i) * combo(K-1,i-1)
        ans = k%(math.pow(10,9)+7)
        print("%d" %(ans))

Buggy submission (verdict: Runtime Error):
import math
N, K = list(map(int, input().split()))

def combo(n, k):
    x = math.factorial(n)//(math.factorial(k)*math.factorial(n-k))
    return x

for i in range(1,K+1):
    n = combo(N-K+1,i)
    k = n * combo(K-1,i-1)
    ans = k%(math.pow(10,9)+7)
    print("%d" %(ans))
Problem p03013 (python)

Fixed submission:
import sys
input=sys.stdin.readline

def fib(n):
    a, b = 1, 0
    for _ in range(n):
        a, b = a + b, a
    return b

n,m = map(int, input().split())
a = []
for i in range(m):
    a.append(int(input()))
if len(a) >= 2:
    for i in range(m-1):
        if a[i]+1 == a[i+1]:
            print(0)
            exit()

tmp = 0
ans = 1
for i in range(len(a)):
    ans *= fib(a[i]-tmp)
    tmp = a[i]+1
if tmp < n:
    ans *= fib(n-tmp+1)
print(ans%(10**9+7))

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

n,m = map(int, input().split())
a = []
for i in range(m):
    a.append(int(input()))
if len(a) >= 2:
    for i in range(m-1):
        if a[i]+1 == a[i+1]:
            print(0)
            exit()

def fib(n):
    if n <= 1:
        return 1
    return fib(n-1) + fib(n-2)
tmp = 0
ans = 1
for i in range(len(a)):
    ans *= fib(a[i]-tmp-1)
    tmp = a[i]+1
if tmp < n:
    ans *= fib(n-tmp)
print(ans%(10**9+7))
Problem p03038 (python)

Fixed submission:
import sys
input=sys.stdin.readline
import bisect

def main():
    _,M= map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    
    B = []
    for _ in range(M):
        b,c = map(int,input().split())
        B.append((b,c))
    B.sort(key=lambda x: x[1])

    x = 0
    m = 0
    while B:
        b,c = B.pop()
        n = bisect.bisect(A,c,lo=m,hi=min(m+b,len(A)))
        x += (n-m)*c
        m = n

    print(x + sum(A[n:]))

if __name__ == '__main__':
    main()

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

def main():
    _,M= map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    
    B = []
    for _ in range(M):
        b,c = map(int,input().split())
        B.append((b,c))
    B.sort(key=lambda x: x[1])

    x = 0
    while B:
        b,c = B.pop()
        n = bisect.bisect(A,c,hi=b)
        x += n*c
        A = A[n:]

    print(x + sum(A))

if __name__ == '__main__':
    main()
Problem p03053 (python)

Fixed submission:
import sys
input=sys.stdin.readline
H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)

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

f = open(sys.argv[1], "r")
input = f.readline

H,W = map(int, input().split())

b = {}
check = set()
i = 0
for h in range(H):
    for c in input().strip():
        if c == "#":
            b[i] = 1
            check.add(i)
        i += 1
t = 0

#import time
#t1 = time.time()

while len(b) != W*H:
    t += 1
    tb = set()
    #print(len(check))
    for i in check:
        if i-W >= 0:
            tb.add(i-W)
        if i%W > 0:
            tb.add(i-1)
        if i%W < W-1:
            tb.add(i+1)
        if i+W < H*W:
            tb.add(i+W)
    check.clear()
    for i in tb:
        if i not in b:
            check.add(i)
        b[i] = 1
print(t)

#print(time.time()-t1)
Problem p03137 (python)

Fixed submission:
import sys
input=sys.stdin.readline
import math

def main():
    N,_ = map(int, input().split())
    X = list(map(int, input().split()))
    X.sort()
    D = []
    for i in range(len(X)-1):
        D.append(X[i+1] - X[i])
    D.sort(reverse=True)
    D = D[N-1:]
    n = 0
    for d in D:
        n += d
    print(n)

if __name__ == '__main__':
    main()

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

def main():
    N,_ = map(int, input().split())
    X = list(map(int, input().split()))
    X.sort()
    D = []
    for i in range(len(X)-1):
        D.append([i+1] - X[i])
    D.sort(reverse=True)
    D = D[math.ceil(N/2):]
    n = 0
    for d in D:
        n += d[1]
    print(n)

if __name__ == '__main__':
    main()
Problem p02847 (python)

Fixed submission:
s = input()
if s == 'SAT':
    print(1)
if s == 'FRI':
    print(2)
if s == 'THU':
    print(3)
if s == 'WED':
    print(4)
if s == 'TUE':
    print(5)
if s == 'MON':
    print(6)
if s == 'SUN':
    print(7)

Buggy submission (verdict: Runtime Error):
s = int(input())
if s == 'SAT':
    print(1)
if s == 'FRI':
    print(2)
if s == 'THU':
    print(3)
if s == 'WED':
    print(4)
if s == 'TUE':
    print(5)
if s == 'MON':
    print(6)
if s == 'SUN':
    print(7)
Problem p03835 (python)

Fixed submission:
k, s = map(int, input().split())
 
ans = 0
for i in range(k+1):
  for j in range(k+1):
    if 0 <= s - i - j <= k:
    	ans += 1
        
print(ans)

Buggy submission (verdict: Runtime Error):
k, s = map(int, input().split())
ans = 0
for i in range(k+1):
    for j in range(k+1):
		if 0 < s- (i + j) < k:
			ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
k, s = map(int, input().split())
ans = 0
for i in range(k+1):
	for j in range(k+1):
     	for k in range(k+1):
          if i + j + k ==s:
            ans += 1
print(ans)
Problem p03805 (python)

Fixed submission:
from collections import defaultdict


def c():
    n, m = map(int, input().split())
    graph = defaultdict(list)
    for i in range(m):
        a, b = map(int, input().split())
        graph[a].append(b)
        graph[b].append(a)
    stack = []
    count = 0

    stack.append((1, set()))

    while stack:
        val, visited = stack.pop()
        visited.add(val)
        if len(visited) == n:
            count += 1
            continue

        for g in graph[val]:
            if g not in visited:
                stack.append((g, set(visited)))

    print(count)


if __name__ == '__main__':
    c()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

def c():
    n, m = map(int, input().split())
    graph = defaultdict(list)
    a1 = None
    for i in range(n):
        a, b = map(int, input().split())
        if i == 0:
            a1 = a
        graph[a].append(b)
        graph[b].append(a)
    stack = []
    count = 0

    if a1:
        stack.append((a1, set()))

    while stack:
        val, visited = stack.pop()
        visited.add(val)
        if len(visited) == m:
            count += 1
            continue

        for g in graph[val]:
            if g not in visited:
                stack.append((g, set(visited)))

    print(count)


if __name__ == '__main__':
    c()