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

Fixed submission:
import sys
sys.setrecursionlimit(2*10**5)

# 入力
N, M = map(int, input().split())
A, B = zip(*(map(int, input().split()) for _ in range(M)))

# 隣接リスト表現のグラフに変換
E = [[] for _ in range(N + 1)]
for a, b in zip(A, B):
    E[a].append(b)
    E[b].append(a)

# 訪れたことがあるかどうかのフラグ
v = [i == 1 for i in range(N + 1)]


# 訪れたことのない頂点を深さ優先探索する
def dfs(i, p):
    for j in E[i]:
        if not v[j]:
            v[j] = True
            p.append(j)
            return dfs(j, p)
    else:
        return p


# Hamiltonish Path を求める
p = list(reversed(dfs(1, []))) + [1] + dfs(1, [])

# 出力
ans = '{}\n{}'.format(len(p), ' '.join(map(str, p)))
print(ans)

Buggy submission (verdict: Runtime Error):
# 入力
N, M = map(int, input().split())
A, B = zip(*(map(int, input().split()) for _ in range(M)))

# 隣接リスト表現のグラフに変換
E = [[] for _ in range(N + 1)]
for a, b in zip(A, B):
    E[a].append(b)
    E[b].append(a)

# 訪れたことがあるかどうかのフラグ
v = [i == 1 for i in range(N + 1)]


# 訪れたことのない頂点を深さ優先探索する
def dfs(i, p):
    for j in E[i]:
        if not v[j]:
            v[j] = True
            p.append(j)
            return dfs(j, p)
    else:
        return p


# Hamiltonish Path を求める
p = list(reversed(dfs(1, []))) + [1] + dfs(1, [])

# 出力
ans = '{}\n{}'.format(len(p), ' '.join(map(str, p)))
print(ans)
Problem p03962 (python)

Fixed submission:
# -*- coding: utf-8 -*-
a, b, c = map(int, input().split())

ans = len({a, b, c})
print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a, b, c = map(int, input().split())

ans = len({a, b, c})
print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a, b, c = map(int, input().split())

ans = len({a, b, c})
print(ans)
Problem p02583 (python)

Fixed submission:
n = int(input())
l = list(map(int,input().split(" ")))
ans = 0

for i in range(n):
  for j in range(n):
    for k in range(n):
      if l[i] < l[j] & l[j] < l[k]:
        if l[i] != l[j] != l[k]:
          if l[i] + l[j] + l[k] > max(l[i],l[j],l[k])*2:
            ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
L = list(map(int,input().split("" )))
S = set(L)
X = []

if len(S) < 3:
  print(0)
else:
  for i in S:
    L.count(i) > 1:
      X.append(L.count(i))
  ans = len(S)*len(S-1)*len(S-2)
  for i in X:
    ans *= i
  print(ans)
Problem p02600 (python)

Fixed submission:
print([8,7,6,5,4,3,2,1][(int(input())-400) // 200 ])

Buggy submission (verdict: Runtime Error):
print([8,7,6,5,4,3,2,1][(input()-400) // 200 ])
Problem p02642 (python)

Fixed submission:
N=int(input())
ls=list(map(int,input().split()))
ls.sort()

#定数倍のやつに＋１する
M=max(ls)
A=[0]*(M+1)
for i in range(N):
  a=M//ls[i]
  for j in range(1,a+1):
    if A[j*ls[i]]<=2:
      A[j*ls[i]]+=1
    
ans=0     
for i in range(len(ls)):
  if A[ls[i]]==1:
    ans+=1
print(ans)

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

#重複したやつ除く
ls_A.sort()
ls=[]
for i in range(N):
  if i==0:
    if ls_A[0]!=ls_A[1]:
      ls.append(ls_A[0])
  elif i==N-1:
    if ls_A[N-1]!=ls_A[N-2]:
      ls.append(ls_A[N-1]) 
  else:
    if ls_A[i]!=ls_A[i-1] and ls_A[i]!=ls_A[i+1]:
      ls.append(ls_A[i])       

#定数倍のやつに＋１する
if not ls:
  print(0)
else:
  A=[0]*(max(ls)+1)
  for i in range(len(ls)):
    a=1
    while ls[i]*a<=max(ls):
      A[ls[i]*a]+=1
      a+=1
  ans=0    
  for i in range(len(ls)):
    if A[ls[i]]==1:
      ans+=1
  print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
ls_A=list(map(int,input().split()))
ls_A.sort()
ls=[]
for i in range(N):
  if i==0:
    if ls_A[0]!=ls_A[1]:
      ls.append(ls_A[0])
  if i==N-1:
    if ls_A[N-1]!=ls_A[N-2]:
      ls.append(ls_A[N-1]) 
  else:
    if ls_A[i]!=ls_A[i-1] and ls_A[i]!=ls_A[i+1]:
      ls.append(ls_A[i])       
    
ans=0
for i in range(len(ls)):
  for j in range(i):
    if ls[i]%ls[j]==0:
      break
    else:
      continue
  else:
    ans+=1
print(ans)
Problem p02684 (python)

Fixed submission:
N, K = map(int,input().split())
ls_pass = [0]+list(map(int,input().split()))
a=1
b=0

ls=["ンゴ"]+[0]+["ンゴ"]*(N-1)
ls_past=[1]
for i in range(1,N*3):
  b=a
  a=ls_pass[a]
  if ls[a]!="ンゴ":
    ls_cicle=ls_past[ls[a]:i]
    print(ls_cicle[(K-i)%len(ls_cicle)])
    break
  elif i==K:
    print(a)
    break  
  else:
    ls_past.append(a)
    ls[a]=i

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
ls_pass = list(map(int,input().split()))
ls_pass.insert(0,0)
a=1
b=0
ls_past=[1]
for i in range(1,N+1):
  b=a
  a=ls_pass[a]
  if b==a:
    print(a)
    break
  elif a in ls_past:
    c=ls_past.index(a)
    ls_cicle=ls_past[c:i]
    print(ls_cicle[(K-i)%(i-c)])
    break
  elif i=K:
    print(a)
    break
  else:
    ls_past.append(a)

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
List = list(map(int,input().split()))
Newlist = [1]
a=1
for i in range(N):
    a = List[a-1]
    if a==Newlist[i-1]:
        print(a)
        break
    elif a in Newlist:
        Cicle = Newlist[Newlist.index(a):Newlist[i-1]]
        print(Cicle[(K-i)%len(Cicle)-1])
        break
    else:
        Newlist.append(a)
else:
  print(a)

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
List = list(map(int,input().split()))
Newlist = [1]
a=1
for i in range(N):
    a = List[a-1]
    if a==Newlist[i-1]:
        print(a)
        break
    elif a in Newlist:
        Cicle = Newlist[Newlist.index(a):Newlist[i-1]]
        print(Cicle[(K-i)%len(Cicle)-1])
        break
    else:
        Newlist.append(a)
Problem p02690 (python)

Fixed submission:
X=int(input())
I=J=0
for i in range(-300,300):
  for j in range(-300,300):
    if i**5-j**5==X:
      I=i
      J=j
      break
print(I,J)

Buggy submission (verdict: Runtime Error):
X=int(input())
A=0
for a in range(X):
  if (a+1)**5-a**5 <= X <= (a+1)**5+a**5:
    A = a
    break

for b in range(-A,A+1):
  if (A+1)**5-b**5 == X:
    B=b
    break   
    
print(A+1,B)

Buggy submission (verdict: Runtime Error):
X=int(input())
A=0
for a in range(X):
  if (a+1)**5-a**5 <= X <= (a+1)**5+a**5:
    A = a
    break

for b in range(-A,A+1):
  if (A+1)**5-b**5 == X:
    B=b
    break   
    
print(A+1,B)

Buggy submission (verdict: Runtime Error):
B=0
for b in range((a+1)**5-a**5,(a+1)**+a**5+1):
  if (a+1)**5-b**5 == X:
    B=b
    break

print(A+1, B)
Problem p02705 (python)

Fixed submission:
R=int(input())
X=3.14159265*2*R
print(X)

Buggy submission (verdict: Runtime Error):
X = 3.14159265*2*R
print(X)

Buggy submission (verdict: Runtime Error):
X = 3.12159265*2*R
print(X)
Problem p02727 (python)

Fixed submission:
X,Y,A,B,C=map(int,input().split())
ls_a=sorted(list(map(int,input().split())))
ls_b=sorted(list(map(int,input().split())))
ls_c=sorted(list(map(int,input().split())))
ls_x=ls_a[A-X:A]
ls_y=ls_b[B-Y:B]
ls_c.reverse()

ans=sum(ls_x)+sum(ls_y)
a=b=c=0
for _ in range(min([X+Y,C])):
  if a==len(ls_x):
    m=min([ls_y[b],ls_c[c]])
    if m==ls_y[b]:
      ans+=(-ls_y[b]+ls_c[c])
      b+=1
      c+=1
    else:
      break
  elif b==len(ls_y):
    m=min([ls_x[a],ls_c[c]])
    if m==ls_x[a]:
      ans+=(-ls_x[a]+ls_c[c])
      a+=1
      c+=1
    else:
      break
  else:    
    m=min([ls_x[a],ls_y[b],ls_c[c]])
    if m==ls_x[a]:
      ans+=(-ls_x[a]+ls_c[c])
      a+=1
      c+=1
    elif m==ls_y[b]:
      ans+=(-ls_y[b]+ls_c[c])
      b+=1
      c+=1
    else:
      break
print(ans)

Buggy submission (verdict: Runtime Error):
X,Y,A,B,C=map(int,input().split())
ls_a=sorted(list(map(int,input().split())))
ls_b=sorted(list(map(int,input().split())))
ls_c=sorted(list(map(int,input().split())))
ls_x=ls_a[A-X:A]
ls_y=ls_b[B-Y:B]
ls_c.reverse()

ans=sum(ls_x)+sum(ls_y)
a=b=c=0
for _ in range(X+Y):
  if a==len(ls_x):
    m=min([ls_y[b],ls_c[c]])
    if m==ls_y[b]:
      ans+=(-ls_y[b]+ls_c[c])
      b+=1
      c+=1
    else:
      break
  elif b==len(ls_y):
    m=min([ls_x[a],ls_c[c]])
    if m==ls_x[a]:
      ans+=(-ls_x[a]+ls_c[c])
      a+=1
      c+=1
    else:
      break
  else:    
    m=min([ls_x[a],ls_y[b],ls_c[c]])
    if m==ls_x[a]:
      ans+=(-ls_x[a]+ls_c[c])
      a+=1
      c+=1
    elif m==ls_y[b]:
      ans+=(-ls_y[b]+ls_c[c])
      b+=1
      c+=1
    else:
      break
print(ans)

Buggy submission (verdict: Runtime Error):
X,Y,A,B,C=map(int,input().split())
ls_a=sorted(list(map(int,input().split())))
ls_b=sorted(list(map(int,input().split())))
ls_c=sorted(list(map(int,input().split())))
ls_x=ls_a[A-X:A]
ls_y=ls_b[B-Y:B]
ls_c.reverse()

ans=sum(ls_x)+sum(ls_y)
a=b=c=0
for i in range(C):
  m=min([ls_x[a],ls_y[b],ls_c[c]])
  if m==ls_x[a]:
    ans+=(-ls_x[a]+ls_c[c])
    a+=1
    c+=1
  elif m==ls_y[b]:
    ans+=(-ls_y[b]+ls_c[c])
    b+=1
    c+=1
  else:
    break
print(ans)
Problem p02780 (python)

Fixed submission:
N,K=map(int,input().split())
ls=list(map(int,input().split()))
ls_p=[(ls[i]+1)/2 for i in range(N)]
a=0
for i in range(K):
  a+=ls_p[i]
b=a  
for i in range(N-K):
  c=a+ls_p[i+K]-ls_p[i]
  b=max([b,c])
  a=c
print(b)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
ls=list(map(int,input().split()))
ls_p=[(ls[i]+1)/2 for i in range(N)]
a=0
for i in range(K):
  a+=ls_p[i]
for i in range(N-K):
  c=a+ls_p[i+K]-ls_p[i]
  b=max([a,c])
  a=c
print(b)
Problem p02787 (python)

Fixed submission:
H, N = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(N)]

dp = [0]*(H+1)
for i in range(1, H+1):
  for j in range(N):
    if j == 0:
      if ls[j][0] <= i:
        dp[i] = dp[i-ls[j][0]] + ls[j][1]
      else:
        dp[i] = ls[j][1]    
    else:
      if ls[j][0] <= i:
        dp[i] = min([dp[i], dp[i-ls[j][0]] + ls[j][1]])
      else:
        dp[i] = min([dp[i], ls[j][1]])
        
print(dp[H])

Buggy submission (verdict: Runtime Error):
H, N = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(N)]

dp = [0]*(H+1)
for i in range(1, H+1):
  for j in range(N):
    if j == 0:
      dp[i] = dp[i-ls[j][0]] + ls[j][1]
    else:
      if ls[j][0] <= i:
        dp[i] = min([dp[i], dp[i-ls[j][0]] + ls[j][1]])
      else:
        dp[i] = min([dp[i], ls[j][1]])
        
print(dp[H])
Problem p03361 (python)

Fixed submission:
H, W = map(int,input().split())
List = [list("." +input()+ ".") for i in range(H)]
B = ["."]*(W+2)
List.insert(0,B)
List.append(B)

for i in range(1,H+1):
  for j in range(1,W+1):
    if List[i][j]=="#" and List[i-1][j]==List[i][j-1]\
        ==List[i][j+1]==List[i+1][j]==".":
      print("No")
      break
  else:
    continue
  break  

else:print("Yes")

Buggy submission (verdict: Runtime Error):
H, W = map(int,input().split())
List = [list("." +input()+ ".") for i in range(H)]
B = ["."]*(W+2)
List.insert(0,B)
List.append(B)

for i in range(1,W+1):
  for j in range(1,H+1):
    if List[i][j]=="#" and List[i-1][j]==List[i][j-1]\
        ==List[i][j+1]==List[i+1][j]==".":
      print("No")
      break
  else:
    continue
  break  

else:print("Yes")
Problem p02628 (python)

Fixed submission:
n, k = input().split()
n = int(n)
k = int(k)
listnum = input().split()
newlist = []
sumnum = 0

listnum = [int(n) for n in listnum]
newlist = sorted(listnum)
for b in range(k):
    sumnum = sumnum + newlist[b]
print(sumnum)

Buggy submission (verdict: Runtime Error):
n, k = input().split()
n = int(n)
k = int(k)
listnum = []
newlist = []
sumnum = 0
for a in range(n):
    listnum.append(int(input())
newlist = sorted(listnum)
for b in range(k):
    sumnum = sumnum + list[0]
print(sumnum)
Problem p02616 (python)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
d1, d2 = sorted([q for q in a if q > 0], reverse=True), sorted([q for q in a if q < 0])
C = 1000000007
if len(d1)+len(d2) < k:
    print(0)
elif k == n:
    ans = 1
    for q in a:
        ans = ans*q % C
    print(ans)
elif len(d1) == 0 and k % 2 == 0:
    ans = 1
    for q in range(k):
        ans = ans*d2[q] % C
    print(ans)
elif len(d1) == 0 and len(d2) < n:
    print(0)
elif len(d1) == 0:
    ans = 1
    for q in range(len(d2)-1, len(d2)-k-1, -1):
        ans = ans*d2[q] % C
    print(ans)
elif len(d2) == 0:
    ans = 1
    for q in range(k):
        ans = ans*d1[q] % C
    print(ans)
else:
    ind = 0
    ans, now, w = 0, 0, min(k+1, len(d2)+1)
    for q in range(max(0, (k-len(d1)+1)//2*2), w, 2):
        if now == 0:
            """now = 1
            for q1 in range(q):
                now *= d2[q1]
            for q1 in range(k-q):
                now *= d1[q1]
            ans = now"""
            now, ind = 1, q
        else:
            if d1[k-q+1]*d1[k-q] <= d2[q-2]*d2[q-1]:
                ind = q
    ans = 1
    for q in range(ind):
        ans = ans*d2[q] % C
    for q in range(k-ind):
        ans = ans*d1[q] % C
    print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
d1, d2 = sorted([q for q in a if q > 0], reverse=True), sorted([q for q in a if q < 0])
C = 1000000007
if len(d1)+len(d2) < k:
    print(0)
elif k == n:
    ans = 1
    for q in a:
        ans = ans*q % C
    print(ans)
elif len(d1) == 0 and k % 2 == 0:
    ans = 1
    for q in range(k):
        ans = ans*d2[q] % C
    print(ans)
elif len(d1) == 0 and len(d2) < n:
    print(0)
elif len(d1) == 0:
    ans = 1
    for q in range(len(d2)-1, len(d2)-k-1, -1):
        ans = ans*d2[q] % C
    print(ans)
elif len(d2) == 0:
    ans = 1
    for q in range(k):
        ans = ans*d1[q] % C
    print(ans)
else:
    ind = 0
    ans, now, w = 0, 0, min(k+1, len(d2)+1)
    for q in range(max(0, (k-len(d1)+1)//2*2), w, 2):
        if now == 0:
            """now = 1
            for q1 in range(q):
                now *= d2[q1]
            for q1 in range(k-q):
                now *= d1[q1]
            ans = now"""
            now = 1
        else:
            if d1[k-q+1]*d1[k-q] <= d2[q-2]*d2[q-1]:
                ind = q
    ans = 1
    for q in range(ind):
        ans = ans*d2[q] % C
    for q in range(k-ind):
        ans = ans*d1[q] % C
    print(ans)
Problem p02553 (python)

Fixed submission:
import numpy as np
if __name__ == "__main__":
    a, b, c, d=(int(x) for x in input().split())
    arr = np.array([a*c, a*d, b*c, b*d])
    print(arr.max())

Buggy submission (verdict: Runtime Error):
import numpy as np
if __name__ == "__main__":
    a, b, c, d=(int(x) for x in input().split())
    arr = [a*c, a*d, b*c, b*d]
    print(arr.max())
Problem p02765 (python)

Fixed submission:
_input = input()
number = _input.split()
N = int(number[0])
R = int(number[1])
if N<10:
  R += 100 * (10-N)
print(R)

Buggy submission (verdict: Runtime Error):
_input = input()
number = _input.split()
N = number[0]
R = number[1]
if N<10:
  R += 100 * (10-N)
print(R)

Buggy submission (verdict: Runtime Error):
import os
import sys
import numpy 

if _name_=='__main__':
  _input = input()
  _input = _input.split()
  N = _input[0]
  R = _input[1]
  if N<10:
    R -= 100 * (10-N)
  print(R)
Problem p03369 (python)

Fixed submission:
s=input()
ans=700
for i in s:
  if i=='o':
    ans+=100
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
c=0
if(s[0]=='o')c+=700
if(s[1]=='o')c+=100
if(s[2]=='o')c+=100
print(c)
Problem p02789 (python)

Fixed submission:
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N, M = rl()

if N == M:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

if N == M:
    print('Yes')
else:
    print('No')
Problem p02823 (python)

Fixed submission:
import sys
input = sys.stdin.readline
N, A, B = map(int, input().split())

if (B-A) % 2 == 0:
	print((B - A) // 2)
else:
	n = min(A-1, N-B) + (B-A-1)//2 + 1
	print(n)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, A, B = map(int, input())

if (A - B) % 2 == 0:
	print((A - B) // 2)
else:
	n = min(A-1, N-B) + (B-A-1)//2 + 1
	print(n)
Problem p02937 (python)

Fixed submission:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

s = rs()
t = rs()


import collections
pos = collections.defaultdict(list)
for i, c in enumerate(s):
	pos[c].append(i)

import bisect

num = 0
cur = -1

for c in t:
	if c not in pos:
		print(-1)
		exit()
	i = bisect.bisect_right(pos[c], cur)
	if i == len(pos[c]):
		i = 0
		num += 1
	cur = pos[c][i]
print(num*len(s)+cur+1)

Buggy submission (verdict: Runtime Error):
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

s = rs()
t = rs()


import collections
pos = collections.defaultdict(list)
for i, c in enumerate(s):
	pos[c].append(i)

import bisect

def bisect_right(arr, x):
    # a_i <= x < a_{i+1}
    l, r = 0, len(arr)
    while r - l > 1:
        c = (r + l) // 2
        if x >= arr[c]:
            l = c
        else:
            r = c
    return r

num = 0
cur = -1

for c in t:
	if c not in pos:
		print(-1)
		exit()
	#i = bisect.bisect_right(pos[c], cur)
	i = search(pos[c], cur)
	if i == len(pos[c]):
		i = 0
		num += 1
	cur = pos[c][i]
print(num*len(s)+cur+1)
Problem p02883 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
f.sort(reverse=1)
su=ok=ng=0
for i in range(n):
  ok=max(ok,a[i]*f[i])
  su+=a[i]
if su<=k:print(0);exit()
while ng+1<ok:
  mid=(ok+ng)//2
  h=0
  for i in range(n):
    r=a[i]-(mid//f[i])
    if (r<0):
      r=0
    h+=r
  if h<=k:ok=mid
  else:ng=mid
print(ok)

Buggy submission (verdict: Runtime Error):
INPUT
3 5
4 2 1
2 3 1
OUTPUT
2
INPUT
3 8
4 2 1
2 3 1
OUTPUT
0
INPUT
11 14
3 1 4 1 5 9 2 6 5 3 5
8 9 7 9 3 2 3 8 4 6 2
OUTPUT
12

n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
f.sort(reverse=1)
su=ok=ng=0
for i in range(n):
  ok=max(ok,a[i]*f[i])
  su+=a[i]
if su<=k:print(0);exit()
while ng+1<ok:
  mid=(ok+ng)//2
  h=0
  for i in range(n):
    h+=max(a[i]-(mid//f[i]), 0)
  if h<=k:ok=mid
  else:ng=mid
print(ok)

Buggy submission (verdict: Runtime Error):
        n,k=map(int,input().split())
        a=list(map(int,input().split()))
        f=list(map(int,input().split()))
        a.sort()
        f.sort(reverse=1)
        su=ok=ng=0
        for i in range(n):
          ok=max(ok,a[i]*f[i])
          su+=a[i]
        if su<=k:print(0);exit()
        while ng+1<ok:
          mid=(ok+ng)//2
          h=0
          for i in range(n):
            h+=a[i]-(f[i]/mid)
          if h<=k:ok=mid
          else:ng=mid
        print(ok)
Problem p02902 (python)

Fixed submission:
from collections import deque
N,M=map(int,input().split())
G=[[] for i in range(N)]
for i in range(M):
	a,b=map(int,input().split())
	G[a-1].append(b-1)
deg=[0 for i in range(N)]
for i in range(N):
	for p in G[i]:
		deg[p]+=1
q=deque(i for i in range(N) if deg[i]==0)
res=[]
while q:
	u=q.popleft()
	res.append(u)
	for v in G[u]:
		deg[v]-=1
		if deg[v]==0:
			q.append(v)
if len(res)==N:
	print(-1)
	exit()
X={i for i in range(N)}
for st in range(N):
	pre=[-1 for i in range(N)]
	q=deque([st])
	flag=0
	while(q):
		r=q.popleft()
		for p in G[r]:
			if pre[p]==-1:
				pre[p]=r
				q.append(p)
			if pre[st]!=-1:
				Y={st}
				tmp=pre[st]
				while(tmp!=st):
					Y.add(tmp)
					tmp=pre[tmp]
				if len(Y)<len(X):
					X={i for i in Y}
				flag=1
				break
		if flag:
			break
print(len(X))
for i in X:
	print(i+1)

Buggy submission (verdict: Runtime Error):
from collections import deque
N,M=map(int,input().split())
G=[[] for i in range(N)]
for i in range(M):
	a,b=map(int,input().split())
	G[a-1].append(b-1)
deg=[0 for i in range(N)]
for i in range(N):
	for p in G[i]:
		deg[p]+=1
q=deque(i for i in range(N) if deg[i]==0)
res=[]
while q:
	u=q.popleft()
	res.append(u)
	for v in G[u]:
		deg[v]-=1
		if K[v]==0:
			q.append(v)
if len(res)==N:
	print(-1)
	exit()
X={i for i in range(N)}
for st in range(N):
	pre=[-1 for i in range(N)]
	q=deque([st])
	flag=0
	while(q):
		r=q.popleft()
		for p in G[r]:
			if pre[p]==-1:
				pre[p]=r
				q.append(p)
			if before[st]!=-1:
				Y={st}
				tmp=pre[st]
				while(tmp!=st):
					Y.add(tmp)
					tmp=before[tmp]
				if len(Y)<len(X):
					X={i for i in Y}
				flag=1
				break
		if flag:
			break
print(len(X))
for i in X:
	print(i+1)
Problem p02554 (python)

Fixed submission:
def main():
    N = int(input())
    print((10**N - 9**N - 9**N + 8**N)%(10**9 + 7))

main()

Buggy submission (verdict: Runtime Error):
def main():
    N = input()
    print((10 ** N - 9 ** N - 9 ** N + 8 ** N)%(10**9 + 7))

main()
Problem p02576 (python)

Fixed submission:
import math
N, X, T = map(int, input().split())

print(T * math.ceil(N / X))

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

while len(N) > 1:
    M = sum(int(N[i]) for i in range(len(N)))
    N = str(M)

if M == 9 or M == 0:
    print('Yes')
else:
    print('No')
Problem p02999 (python)

Fixed submission:
x, a = map(int, input().split())
print(0 if x < a else 10)

Buggy submission (verdict: Runtime Error):
x, a = map(int. input().split())
print(0 if x < a else 10)
Problem p03000 (python)

Fixed submission:
n, x = map(int, input().split())
l = list(map(int, input().split()))
d = [0]
for li in l:
  d.append(d[-1] + li)
print(len([di for di in d if di <= x]))

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
l = list(map(int, input().split()))
d = [0]
for li in l:
  d.append(d[-1] + li)
print(len([di for di in d if d <= x]))
Problem p02603 (python)

Fixed submission:
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    dp = [0 for j in range(N+1)]
    dp[0] = 1000
    for i in range(1, N+1):
        for j in range(i):
            dp[i] = max(dp[i], dp[j])
        for j in range(1, i):
            dp[i] = max(dp[i], dp[j] % A[j-1]+A[i-1]*(dp[j]//A[j-1]))
    ans = dp[N]
    print(ans)


if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
def solve():
    N=int(input())
    A=list(map(int,input().split()))
    mini,maxi=min(A),max(A)
    cnt=1000//mini
    print(maxi*cnt+1000%mini)
    
if __name__=="__main__"
    solve()