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

Fixed submission:
import re
def main():
    c = input()
    if re.match("[aiueo]",c):
        print('vowel')
    else:
        print("consonant")

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import re
def main():
    c = input()
    if re.match("[aiueo]",c):
        print('vowel')
    else:
        print(consonant)

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

Fixed submission:
def main():
    n = int(input())
    t = []
    a = []
    for i in range(n):
        in_t,in_a = map(int,input().split(' '))
        t.append(in_t)
        a.append(in_a)
    if n == 1:
        return t[0]+a[0]
    tmp_t = t[0]
    tmp_a = a[0]
    for i in range(1,n):
        if tmp_t%t[i] != 0:
            x = (tmp_t - tmp_t%t[i] + t[i])//t[i]
        else:
            x = tmp_t//t[i]

        if tmp_a%a[i] != 0:
            y = (tmp_a - tmp_a%a[i] + a[i])//a[i]
        else:
            y = tmp_a//a[i]

        if x <= y:
            x = y
        else:
            y = x
        tmp_t = t[i]*x
        tmp_a = a[i]*y
    return tmp_t+tmp_a

if __name__ == '__main__':
    print(main())

Buggy submission (verdict: Runtime Error):
from collections import deque
def main():
    n = int(input())
    t = []
    a = []
    for i in range(n):
        in_t,in_a = map(int,input().split(' '))
        t.append(in_t)
        a.append(in_a)
    q= deque()
    q.append([t[0],a[0]])

    for i in range(1,n):
        while True:
            tmp_t,tmp_a=q.popleft()
            if tmp_t/tmp_a == t[i]/a[i]:
                q.clear()
                q.append([tmp_t,tmp_a])
                break
            elif tmp_t/tmp_a < t[i]/a[i]:
                q.append([tmp_t+1,tmp_a])
            else:
                q.append([tmp_t,tmp_a+1])
    return tmp_t+tmp_a

if __name__ == '__main__':
    print(main())
Problem p04014 (python)

Fixed submission:
n = int(input())
s = int(input())

def f(b,n):
  if n < b:
    return n
  return f(b,n//b) + n%b


def solve(n,s):
  if s > n:
    return -1
  if s == n:
    return n+1
  nsq = int(n**0.5 + 1)
  for b in range(2,nsq+1):
    if f(b,n) == s:
      return b
  # 2桁で作れるかどうか
  # n = bx+y, s = x+y, x,y < b
  # n - s = (b-1)x, x < b
  m = n-s
  msq = int(m**0.5+1)
  for x in range(msq,0,-1):
    if m%x:
      continue
    b = m//x+1
    if f(b,n) == s:
      return b
  return -1
  
answer = solve(n,s)
print(answer)

Buggy submission (verdict: Runtime Error):
import math
def f(b,n):
    if n<b:
        return n
    return f(b,n//b)+n%b

def main():
    n=int(input())
    s=int(input())
    if n==s:
        return n+1
    elif n <s:
        return -1
    else:
        for b in range(2,int(math.sqrt(n))+2):
            if f(b,n)==s:
                print(b)
                exit()
        for p in range(int(math.sqrt(n-s)+1),0,-1):
            b=(n-s)//p+1
            if f(b,n)==s:
                return b
    return -1

if __name__ == '__main__':
    print(main())

Buggy submission (verdict: Runtime Error):
import math
def f(b,n):
    if n<b:
        return n
    return f(b,n//b)+n%b

def main():
    n=int(input())
    s=int(input())
    if n==s:
        print(n+1)
        exit()
    elif n <s:
        print(-1)
        exit()
    else:
        for b in range(2,int(math.sqrt(n))+2):
            if f(b,n)==s:
                print(b)
                exit()
        for j in range(int(math.sqrt(n)+1),0,-1):
            b=(n-s)//j+1
            if f(b,n)==s:
                print(int(b))
                exit()
    print(-1)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math
def f(b,n):
    if n<b:
        return n
    return f(b,n//b)+n%b

def main():
    n=int(input())
    s=int(input())
    if n==s:
        print(n+1)
        exit()
    elif n <s:
        print(-1)
        exit()
    else:
        for b in range(2,int(math.sqrt(n))+2):
            if f(b,n)==s:
                print(b)
                exit()
        for j in range(int(math.sqrt(n)+1)+1,0,-1):
            b=(n-s)//j+1
            if f(b,n)==s:
                print(int(b))
                exit()
    print(-1)

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

Fixed submission:
def main():
    s = list(input())
    ans = []
    for i in s:
        if i != "B":
            ans.append(i)
        elif ans:
            ans.pop(-1)
    for i in ans:
        print(i,end='')

if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    s = list(input())
    ans = []
    for i in s:
        if i =='B':
            ans.pop(-1)
        else:
            ans.append(i)
    for i in ans:
        print(i,end='')

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

Fixed submission:
N = int(input())
X = input()
temp = X.count("1")
t = [0, 0, 0]

t[0] = int(X, 2) % (temp-1) if temp != 1 else 0
t[2] = int(X, 2) % (temp+1)
cnt = 0
for i in range(N):
    if X[i] == "1" and temp == 1:
        print(0)
        continue
    if X[i] == "1":
        # p = (1 << (N-i-1)) % (temp-1)
        p = pow(2, N-1-i, temp-1)
        a = (t[0]-p) % (temp-1)
    elif X[i] == "0":
        # m = (1 << (N-i-1)) % (temp+1)
        m = pow(2, N-1-i, temp+1)
        a = (t[2]+m) % (temp+1)
    cnt = 1
    while a > 0:
        a = a % format(a, 'b').count("1")
        cnt += 1
    print(cnt)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import sys
import itertools
import array
import textwrap
import math

N = int(input())
X = input()
temp = X.count("1")
t = [0, 0, 0]
t[0] = int(X, 2) % (temp-1)
# t[1] = int(X, 2) % (temp)
t[2] = int(X, 2) % (temp+1)
# print(X)
cnt = 0
# X = int(X, 2)
# print(X)
for i in range(N):
    if X[i] == "1":
        p = (1 << (N-i-1)) % (temp-1)
        a = (t[0]-p) % (temp-1)
    elif X[i] == "0":
        m = (1 << (N-i-1)) % (temp+1)
        a = (t[2]+m) % (temp+1)
    cnt = 1
    # print(a)
    while a > 0:
        a = a % str(bin(a)).count("1")
        # print(a)
        cnt += 1
    print(cnt)
Problem p02664 (python)

Fixed submission:
from sys import stdin
import sys

T = input()
if T == '?':
    print('D')
    sys.exit()
if T[0] == '?' and T[1] == '?':
    T = 'P'+T[1:]
    # print(T)
t = T[0]
ans = []
if t == '?' and T[1] == 'D':
    ans.append('P')
elif t == '?' and T[1] == 'P':
    ans.append('D')
else:
    ans.append(t)

for i in range(1, len(T)):
    if t == 'P':
        if T[i] == '?':
            ans.append('D')
            t = 'D'
        else:
            ans.append(T[i])
            t = T[i]
    elif t == 'D' and i < len(T)-1 and T[i+1] == '?':
        if T[i] == '?':
            ans.append('P')
            t = 'P'
        else:
            ans.append(T[i])
            t = T[i]
    elif t == 'D' and i < len(T)-1 and T[i+1] == 'D':
        if T[i] == '?':
            ans.append('P')
            t = 'P'
        else:
            ans.append(T[i])
            t = T[i]
    else:
        if T[i] == '?':
            ans.append('D')
            t = 'D'
        else:
            ans.append(T[i])
            t = T[i]
print(''.join(ans))

Buggy submission (verdict: Runtime Error):
from sys import stdin
import sys

T = input()
t = T[0]
ans = []
if t == '?' and T[1] == 'D':
    ans.append('P')
elif t == '?' and T[1] == 'P':
    ans.append('D')
else:
    ans.append(t)

for i in range(1, len(T)):
    if t == 'P':
        if T[i] == '?':
            ans.append('D')
            t = 'D'
        else:
            ans.append(T[i])
            t = T[i]
    elif t == 'D' and i < len(T)-1 and T[i+1] == '?':
        if T[i] == '?':
            ans.append('P')
            t = 'P'
        else:
            ans.append(T[i])
            t = T[i]
    elif t == 'D' and i < len(T)-1 and T[i+1] == 'D':
        if T[i] == '?':
            ans.append('P')
            t = 'P'
        else:
            ans.append(T[i])
            t = T[i]
    else:
        if T[i] == '?':
            ans.append('D')
            t = 'D'
        else:
            ans.append(T[i])
            t = T[i]
print(''.join(ans))
Problem p02684 (python)

Fixed submission:
from sys import stdin
import sys

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = list(map(int, input().split()))
B = [i for i in range(1, N+1)]
d = dict(zip(B, A))
t = [0 for i in range(N)]
d1 = dict(zip(B, t))
temp = 1
cnt = 0
ans = []
for i in range(K):
    d1[d[temp]] = d1.get(d[temp], 0)+1
    if d1.get(d[temp], 0) == 2:
        cnt += 1
        ans.append(d[temp])
        # print(i, d[temp])
    if d1.get(d[temp], 0) == 3:
        break
    temp = d[temp]
    if i == K-1:
        print(temp)
        sys.exit()
cnt1 = 0
for i, v in enumerate(d1):
    if d1[v] == 1:
        cnt1 += 1
# print(cnt, cnt1, d1, temp, ans)
k = K-1-cnt1
print(ans[k % cnt])

Buggy submission (verdict: Runtime Error):
from sys import stdin
import sys

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = list(map(int, input().split()))
B = [i for i in range(1, N+1)]
d = dict(zip(B, A))
t = [0 for i in range(N)]
d1 = dict(zip(B, t))
temp = 1
cnt = 0
ans = []
for i in range(K):
    d1[d[temp]] = d1.get(d[temp], 0)+1
    if d1.get(d[temp], 0) == 2:
        cnt += 1
        ans.append(d[temp])
        # print(i, d[temp])
    if d1.get(d[temp], 0) == 3:
        break
    temp = d[temp]
    if i == K-1:
        print(temp)
        sys.exit()
cnt1 = 0
x = 1/cnt1
for i, v in enumerate(d1):
    if v == 1:
        cnt1 += 1
# print(cnt, cnt1, d1, temp, ans)
k = K-1-cnt1
print(ans[k % cnt])

Buggy submission (verdict: Runtime Error):
from sys import stdin
import sys

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = list(map(int, input().split()))
B = [i for i in range(1, N+1)]
d = dict(zip(B, A))
t = [0 for i in range(N)]
d1 = dict(zip(B, t))
temp = 1
cnt = 0
ans = []
for i in range(K):
    d1[d[temp]] = d1.get(d[temp], 0)+1
    if d1.get(d[temp], 0) == 2:
        cnt += 1
        ans.append(d[temp])
        # print(i, d[temp])
    if d1.get(d[temp], 0) == 3:
        break
    temp = d[temp]
cnt1 = 0
for i, v in enumerate(d1):
    if v == 1:
        cnt1 += 1
# print(cnt, cnt1, d1, temp, ans)
k = K-1-cnt1
print(ans[k % cnt])
Problem p03393 (python)

Fixed submission:
from sys import stdin
import sys
# import itertools
# import math

S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit()
a = [chr(i) for i in range(97, 97+26)]
b = [0 for i in range(26)]
d = dict(zip(a, b))
d1 = d
for i, v in enumerate(S):
    d[v] = d.get(v, 0)+1
for i, v in enumerate(a):
    if d[v] != 1:
        print(S+v)
        sys.exit()
temp = []
temp1 = []

for i in range(25):
    temp1 = []
    temp.append(S[-1-i])
    # print(S[-1-i], S[-1-i-1])
    for k, v in enumerate(temp):
        # print("v="+v)
        # print(S[-1-i-1], ord(S[-1-i-1]), ord(v))
        if S[-1-i-1] < v:
            temp1.append(v)
    # print(temp, temp1)
    if len(temp1) > 0:
        temp1.sort()
        print(S[:-1-i-1]+temp1[0])
        sys.exit()

Buggy submission (verdict: Runtime Error):
from sys import stdin
import sys
# import itertools
# import math

S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit()
a = [chr(i) for i in range(97, 97+26)]
b = [0 for i in range(26)]
d = dict(zip(a, b))
d1 = d
for i, v in enumerate(S):
    d[v] = d.get(v, 0)+1
for i, v in enumerate(a):
    if d[v] != 1:
        print(S+v)
        sys.exit()
temp = []
temp1 = []
x = 10/0
for i in range(26):
    temp1 = []
    temp.append(S[-1-i])
    # print(S[-1-i])
    for i, v in enumerate(temp):
        if S[-1-i-1] < v:
            temp1.append(v)
    if len(temp1) > 0:
        print(S[:-1-i-1]+min(temp1))
        sys.exit()

Buggy submission (verdict: Runtime Error):
from sys import stdin
import sys
# import itertools
# import math

S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit()
a = [chr(i) for i in range(97, 97+26)]
b = [0 for i in range(26)]
d = dict(zip(a, b))
d1 = d
for i, v in enumerate(S):
    d[v] = d.get(v, 0)+1
for i, v in enumerate(a):
    if d[v] != 1:
        print(S+v)
        sys.exit()
temp = []
for i in range(26):
    temp.append(S[-1-i])
    if S[-1-i-1] < min(temp):
        print(S[:-1-i-1]+min(temp))
        sys.exit()
Problem p03071 (python)

Fixed submission:
A, B = map(int , input().split())

if A==B:
    print(A*2)
else:
    print(2*max(A,B)-1)

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

_count=1
max_height=H[0]

for i in range(1,N):
    if max_height <= H[i]:
        _count +=1
        max_height = H[i]
print(_count)
Problem p03076 (python)

Fixed submission:
import math

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
list1 = [A,B,C,D,E]
list2 = [i%10 for i in list1]
min_item=max(list2)
for i in range(1,10):
    if i in list2:
        min_item = min(min_item,i)
min_index = list2.index(min_item)
total_time = 0
time_seq =[]

for i in range(5):
    if i == min_index:
        continue
    time1 = math.ceil(list1[i]/10) * 10
    total_time += time1
    time_seq.append(time1)
    
total_time += list1[min_index]
print(int(total_time))

Buggy submission (verdict: Runtime Error):
import math

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
list1 = [A,B,C,D,E]
list2 = [i%10 for i in list1]
min_item=9
for i in range(1,10):
    if i in list2:
        min_item = min(min_item,i)
min_index = list2.index(min_item)
total_time = 0
time_seq =[]

for i in range(5):
    if i == min_index:
        continue
    time1 = math.ceil(list1[i]/10) * 10
    total_time += time1
    time_seq.append(time1)
    
total_time += list1[min_index]
print(int(total_time))
Problem p03078 (python)

Fixed submission:

X,Y,Z,K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = list(reversed(sorted(A)))
B = list(reversed(sorted(B)))
C = list(reversed(sorted(C)))
abc_list=[]

for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1) * (j+1) * (k+1) <= K:
                abc_list.append(A[i] + B[j] +C[k])
            else:
                break

abc_list = list(reversed(sorted(abc_list)))

for i in range(K):
    print(abc_list[i])

Buggy submission (verdict: Runtime Error):


X,Y,Z,K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = reversed(sorted(A))
B = reversed(sorted(B))
C = reversed(sorted(C))
abc_list=[]

for i in A:
    for j in B:
        for k in C:
            if i * j * k <= K:
                abc_list.append(i+j+k)
            else:
                break

abc_list = reversed(sorted(abc_list))

for i in range(K):
    print(abc_list[i])
Problem p03085 (python)

Fixed submission:
b=input()

e_dict={
  'A':'T',
  'T':'A',
  'G':'C',
  'C':'G'
}

print(e_dict[b])

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

e_dict={
  'A':'T',
  'T':'A',
  'G':'C',
  'C':'G'
}

print(e_dict[b])
Problem p03086 (python)

Fixed submission:
S=input()
max_count=0
for i in range(len(S)):
    if S[i] in ['A','C','G','T']:
        j=0
        while S[i+j] in ['A','C','G','T']:
            max_count=max(max_count,j+1)
            j+=1
            if i+j==len(S):
                break
print(max_count)

Buggy submission (verdict: Runtime Error):
S=input()
max_count=0
for i in range(len(S)):
  if S[i] in [A,C,G,T]:
    j=0
    while S[i+j] in [A,C,G,T]:
      max_count=max(max_count,j)
      j+=1
      if i+j==len(S):
        break
print(max_count)
Problem p03101 (python)

Fixed submission:
H,W = list(map(int, input().split(' ')))
h,w = list(map(int, input().split(' ')))
print((H-h)*(W-w))

Buggy submission (verdict: Runtime Error):
H,W = list(map(int, input().split(' '))
h,w = list(map(int, input().split(' '))
print((H-h)*(W-w))

Buggy submission (verdict: Runtime Error):
H,W = list(map(int, input().split(' ')
h,w = list(map(int, input().split(' ')
pritn((H-h)*(W-w))
Problem p03140 (python)

Fixed submission:
n=int(input())
a=input()
b=input()
c=input()
abc=list('0'*n)
for i in range(n):
    if a[i]==b[i]:
        abc[i]=a[i]
    if b[i]==c[i]:
        abc[i]=b[i]
    if c[i]==a[i]:
        abc[i]=c[i]
    if abc[i]=='0':
        abc[i]=a[i]
count=0
for i in range(n):
    if a[i]!=abc[i]:
        count+=1
    if b[i]!=abc[i]:
        count+=1
    if c[i]!=abc[i]:
        count+=1
print(count)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=input()
b=input()
c=input()
abc=list('0000')
for i in range(n):
    if a[i]==b[i]:
        abc[i]=a[i]
    if b[i]==c[i]:
        abc[i]=b[i]
    if c[i]==a[i]:
        abc[i]=c[i]
count=0
for i in range(n):
    if a[i]!=abc[i]:
        count+=1
    if b[i]!=abc[i]:
        count+=1
    if c[i]!=abc[i]:
        count+=1
print(count)
Problem p03145 (python)

Fixed submission:
c,a,b=map(int,input().split( ))
print(int(a*c/2))

Buggy submission (verdict: Runtime Error):
c,a,b=map(int(input().split()))
print(a*c)
Problem p03155 (python)

Fixed submission:
N=int(input())
H=int(input())
W=int(input())
print((N-H+1)*(N-W+1))

Buggy submission (verdict: Runtime Error):
N=input()
H=input()
W=input()
print((N-H+1)*(N-W+1))
Problem p03587 (python)

Fixed submission:
S=input()

print(S.count('1'))

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

print(S.count(1))
Problem p03609 (python)

Fixed submission:
X, t =list(map(int, input().split( )))
print(max(X-t,0))

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
values=[]
for i in range(min(a), max(a)+1):
    values.append(a.count(i))
    
max_value=0
for i in range(len(values)-2):
    max_value = max(max_value, values[i]+values[i+1]+values[i+2])
print(max_value)
Problem p02775 (python)

Fixed submission:
m = input()[::-1]
n = []
for i in range(len(m)):
    n.append(int(m[i]))

dp = [[0, 0] for _ in range(len(n)+1)]

for i in range(len(n)):
    dp[i+1][0] = min((dp[i][0]+n[i]), (dp[i][1]+n[i]+1))
    if i == 0:
        dp[i+1][1] = dp[i][0]+10-n[i]
    else:
        dp[i+1][1] = min((dp[i][0]+10-n[i]), (dp[i][1]+9-n[i]))

s = len(n)
print(min(dp[s][0], (dp[s][1]+1)))

Buggy submission (verdict: Runtime Error):
n = list(map(int,input()))[::-1]
mon = []
pay = []
ret = []
d = 0
for i in range(len(n)):
    c = d + n[i]
    e = c%10
    mon.append(c)
    if e < 5:
        pay.append(e)
        ret.append(0)
        d = c//10
    elif e == 5:
        if i == len(n):
            pay.append(e)
            ret.append(0)
            d = c//10
        else:
            if n[i+1] < 4:
                pay.append(e)
                ret.append(0)
                d = c//10
            else:
                pay.append(0)
                f = 10-e
                ret.append(f)
                d = c//10 + 1
    else:
        pay.append(0)
        f = 10-e
        ret.append(f)
        d = c//10 + 1
if d == 1:
    pay.append(1)
    

ans = 0
for i in range(len(pay)):
    ans += pay[i]
for j in range(len(ret)):
    ans += ret[j]
    

print(ans)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10000000)
N = int(input())
JU = [-1 for _ in range(N)]

LI = [[] for _ in range(N)]
for _ in range(N-1):
    u,v,w = map(int,input().split())
    W = w%2
    LI[u-1].append([v-1,W])
    LI[v-1].append([u-1,W])
def dfs(x):
    for i in range(len(LI[x])):
        j = LI[x][i][0]
        k = LI[x][i][1]
        if JU[j] == -1:
            if JU[x] == 0:
                if k == 0:
                    JU[j] = 0
                    dfs(j)
                else:
                    JU[j] = 1
                    dfs(j)
            else:
                if k == 0:
                    JU[j] = 1
                    dfs(j)
                else:
                    JU[j] = 0
                    dfs(j)

JU[0] = 0
dfs(0)
for i in range(N):
    print(JU[i])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000000)
N = int(input())
JU = [-1] * N

LI = [[] for _ in range(N)]
for _ in range(N-1):
    u,v,w = map(int,input().split())
    W = w%2
    LI[u-1].append([v-1,W])
    LI[v-1].append([u-1,W])
def dfs(x):
    for i in range(len(LI[x])):
        j = LI[x][i][0]
        k = LI[x][i][1]
        if JU[j] == -1:
            if JU[i] == 0:
                if k == 0:
                    JU[j] = 0
                    dfs(j)
                else:
                    JU[j] = 1
                    dfs(j)
            else:
                if k == 0:
                    JU[j] = 1
                    dfs(j)
                else:
                    JU[j] = 0
                    dfs(j)
	return

JU[0] = 0
dfs(0)
for i in range(N):
    print(JU[i])

Buggy submission (verdict: Runtime Error):
sys.setrecursionlimit(10000000)
N = int(input())
JU = [-1] * N

LI = [[] for _ in range(N)]
for _ in range(N-1):
    u,v,w = map(int,input().split())
    W = w%2
    LI[u-1].append([v-1,W])
    LI[v-1].append([u-1,W])
def dfs(x):
    for i in range(len(LI[x])):
        j = LI[x][i][0]
        k = LI[x][i][1]
        if JU[j] == -1:
            if JU[i] == 0:
                if k == 0:
                    JU[j] = 0
                    dfs(j)
                else:
                    JU[j] = 1
                    dfs(j)
            else:
                if k == 0:
                    JU[j] = 1
                    dfs(j)
                else:
                    JU[j] = 0
                    dfs(j)

for i in range(N):
    if JU[i] == -1:
        JU[i] = 0
        dfs(i)
for i in range(N):
    print(JU[i])
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n, m = map(int, input().split())
dest = [[] for _ in range(n)]
comein = [0 for _ in range(n)]
ro = [True for _ in range(n)]
dp = [0 for _ in range(n)]
for _ in range(m):
	x, y = map(int, input().split())
	dest[x-1].append(y-1)
	comein[y-1] += 1
	ro[y-1] = False

def search(leaf):
	global dp
	for i in dest[leaf]:
		comein[i] -= 1
		dp[i] = max(dp[i], dp[leaf] + 1)
		if comein[i] == 0:
			search(i)
	return

for j in range(n):
	if ro[j] == True:
		search(j)

print(max(dp))

Buggy submission (verdict: Runtime Error):
#dpg
#根になってるものからsearch
#1.行き先にいくための現時点での最長経路と根から来た場合の経路を比較
#2.その枝はもう見なくて良いので削除(行き先に入る枝のカウントを1減らす)
#入る枝がなくなったら根として考えてそっからまたsearch
#計算量はsearchの回数分(m+n)
n, m = map(int, input().split())
dest = [[] for _ in range(n)]
comein = [0 for _ in range(n)]
ro = [True for _ in range(n)]
dp = [0 for _ in range(n)]
for _ in range(m):
	x, y = map(int, input().split())
	dest[x-1].append(y-1)
	comein[y-1] += 1
	ro[y-1] = False

def search(leaf):
	global dp
	for i in dest[leaf]:
		comein[i] -= 1
		dp[i] = max(dp[i], dp[leaf] + 1)
		if comein[i] == 0:
			search(i)
	return

for j in range(n):
	if ro[j] == True:
		search(j)

print(max(dp))

Buggy submission (verdict: Runtime Error):
#dpg
#根になってるものからsearch
#1.行き先にいくための現時点での最長経路と根から来た場合の経路を比較
#2.その枝はもう見なくて良いので削除(行き先に入る枝のカウントを1減らす)
#入る枝がなくなったら根として考えてそっからまたsearch
#計算量はsearchの回数分(m+n)
n, m = map(int, input().split())
dest = [[] for _ in range(n)]
comein = [0 for _ in range(n)]
for _ in range(m):
	x, y = map(int, input().split())
	dest[x-1].append(y-1)
	comein[y-1] += 1
dp = [0 for _ in range(n)]

def search(leaf):
	global dp
	for i in dest[leaf]:
		comein[i] -= 1
		dp[i] = max(dp[i], dp[leaf] + 1)
		if comein[i] == 0:
			search(i)
	return
ro = []
for i in range(n):
	if comein[i] == 0:
		ro.append(i)
if ro != []:
	for j in ro:
		search(j)

print(max(dp))

Buggy submission (verdict: Runtime Error):
#dpg
#根になってるものからsearch
#1.行き先にいくための現時点での最長経路と根から来た場合の経路を比較
#2.その枝はもう見なくて良いので削除(行き先に入る枝のカウントを1減らす)
#入る枝がなくなったら根として考えてそっからまたsearch
#計算量はsearchの回数分(m+n)
n, m = map(int, input().split())
dest = [[] for _ in range(n)]
comein = [0 for _ in range(n)]
for _ in range(m):
	x, y = map(int, input().split())
	dest[x-1].append(y-1)
	comein[y-1] += 1
dp = [0 for _ in range(n)]

def search(leaf):
	global dp
	for i in dest[leaf]:
		comein[i] -= 1
		dp[i] = max(dp[i], dp[leaf] + 1)
		if comein[i] == 0:
			search(i)
	return
ro = []
for i in range(n):
	if comein[i] == 0:
		ro.append(i)
for j in ro:
	search(j)

print(max(dp))