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

Fixed submission:
import math

N , K = map(int, input().split())
flag = "F"
if N !=0:
    while 1:
        lenN = int (math.log10(N) + 1)
        lenK = int (math.log10(K) + 1)
        N = abs(N-K*(10**abs(lenN-lenK-1)))
        lenN = int (math.log10(N) + 1)
        if abs(lenN-lenK)<2:
            break



        
while 1:
    
    
    a = N
    N = abs(N - K)
    

    if a<=K and N <= K:
        if a < N:
            result = a
            flag="T"
        else:
            result = N
            flag="T"
    if flag == "T":
        break
print(result)

Buggy submission (verdict: Runtime Error):
import math

N , K = map(int, input().split())
flag = "F"

while 1:
    lenN = int (math.log10(N) + 1)
    lenK = int (math.log10(K) + 1)
    N = abs(N-K*(10**abs(lenN-lenK-1)))
    lenN = int (math.log10(N) + 1)
    if abs(lenN-lenK)<2:
        break
        
while 1:
    
    
    a = N
    N = abs(N - K)
    

    if a<=K and N <= K:
        if a < N:
            result = a
            flag="T"
        else:
            result = N
            flag="T"
    if flag == "T":
        break
print(result)

Buggy submission (verdict: Runtime Error):
import math

N , K = map(int, input().split())
flag = "F"

lenN = int (math.log10(N) + 1)
lenK = int (math.log10(K) + 1)

N = abs(N-K*(10**abs(lenN-lenK+1)))
while 1:
    
    
    a = N
    N = abs(N - K)
    

    if a<=K and N <= K:
        if a < N:
            result = a
            flag="T"
        else:
            result = N
            flag="T"
    if flag == "T":
        break
print(result)

Buggy submission (verdict: Runtime Error):
import math

N , K = map(int, input().split())
flag = "F"

lenN = int (math.log10(N) + 1)
lenK = int (math.log10(K) + 1)
N = abs(N-K*(abs(lenN-lenK))) 

while 1:
    
    
    a = N
    N = abs(N - K)
    

    if a<=K and N <= K:
        if a < N:
            result = a
            flag="T"
        else:
            result = N
            flag="T"
    if flag == "T":
        break
print(result)

Buggy submission (verdict: Runtime Error):
N , K = map(int, input().split())
flag = "F"

lenN = len(N)
lenK = len(K)
N = abs(N-K*(abs(len(N)-len(K)))) 

while 1:
    
    
    a = N
    N = abs(N - K)
    

    if a<=K and N <= K:
        if a < N:
            result = a
            flag="T"
        else:
            result = N
            flag="T"
    if flag == "T":
        break
print(result)
Problem p02921 (python)

Fixed submission:
S = list(input())
T = list(input())
c = 0
for x in range(len(S)):
  if S[x] == T[x]:
    c += 1
print(c)

Buggy submission (verdict: Runtime Error):
S = list(map(int,input().split()))
T = list(map(int,input().split()))
c = 0
for x in range(S):
  if S[x] == T[x]:
    c += 1
print(c)
Problem p02923 (python)

Fixed submission:
N = int(input())
h = list(map(int, input().split()))
c = []
tmp = 0
for x in reversed(range(len(h))):
  if len(h) == 1:
    c.append(0)
  elif h[x] <= h[x-1]:
    tmp += 1
  else:
    c.append(tmp)
    tmp = 0
if len(c) == 0:
  c.append(tmp-1)
print(sorted(c)[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))
c = []
tmp = 0
for x in reversed(range(len(h))):
  if len(h) == 1:
    c.append(0)
  elif h[x] <= h[x-1]:
    tmp += 1
  else:
    c.append(tmp)
    tmp = 0
print(sorted(c)[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))
c = []
tmp = 0
for x in reversed(range(len(h))):
  if len(h) == 1:
    c.append(h[0])
  elif h[x] <= h[x-1]:
    tmp += 1
  else:
    c.append(tmp)
    tmp = 0
print(sorted(c)[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))
c = []
tmp = 0
for x in range(len(h)-1, -1, -1):
  if len(h) == 1:
    c.append(h[0])
  elif h[x] <= h[x-1]:
    tmp += 1
  else:
    c.append(tmp)
    tmp = 0
print(sorted(c)[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))
c = []
tmp = 0
for x in range(len(h)-1, -1, -1):
  if len(h) == 1:
    c.append(h[0])
  elif h[x] <= h[x-1]:
    tmp += 1
  else:
    c.append(tmp)
    tmp = 0
print(max(c))

Buggy submission (verdict: Runtime Error):
N = input()
h = list(map(str, input().split()))
c = []
tmp = 0
for x in range(len(h)-1, -1, -1):
  if h[x] <= h[x-1]:
    tmp += 1
  else:
    c.append(tmp)
    tmp = 0
print(max(c))

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))
c = []
tmp = 0
for x in range(len(h)-1, -1, -1):
  if h[x] <= h[x-1]:
    tmp += 1
  else:
    c.append(tmp)
    tmp = 0
print(max(c))
Problem p03060 (python)

Fixed submission:
N = int(input())
values = list(map(int,input().split()))
costs = list(map(int,input().split()))
dictionary = []
for v in range(N):
  dictionary.append([values[v],costs[v]])
x,y=0,0
result = []
for i in range(N):
  if dictionary[i][0] - dictionary[i][1]>0:
    result.append(dictionary[i][0]-dictionary[i][1])
print(sum(result))

Buggy submission (verdict: Runtime Error):
N = int(input())
values = list(map(int,input().split()))
costs = list(map(int,input().split()))
dictionary = {}
for v in range(N):
  dictionary.setdefault(values[v], []).append(costs[v])
revarse_keys = sorted(dictionary, reverse=True, key=int)
x,y = 0,0
for i in range(N):
  if revarse_keys[i] > int(dictionary[revarse_keys[i]][0]) and (i+1)<=N:
    x = revarse_keys[i]+revarse_keys[i+1]
    y = dictionary[revarse_keys[i]][0]+dictionary[revarse_keys[i+1]][0]
    break
print(x-y)
Problem p03086 (python)

Fixed submission:
S = list(input())
acgt = ['A', 'C', 'G', 'T']
lengths = []
l = 0
for x in S:
  if x in acgt:
    l += 1
  else:
    lengths.append(l)
    l = 0

if len(lengths) == 0 or l > 0:
  lengths.append(l)

print(max(lengths))

Buggy submission (verdict: Runtime Error):
S = list(input())
acgt = ['A', 'C', 'G', 'T']
lengths = []
l = 0
for x in S:
  if x in acgt:
    l += 1
  else:
    lengths.append(l)
    l = 0
print(max(lengths))

Buggy submission (verdict: Runtime Error):
S = list(input())
acgt = ['A','C','G','T']
lengths = []
length = 0
for s in S:
  if s in acgt:
    length+=1
  else:
    lengths.append(length)
print(max(lengths))
Problem p03125 (python)

Fixed submission:
A, B = map(int, input().split())
print(A+B if B % A == 0 else B-A)

Buggy submission (verdict: Runtime Error):
def main()
  a = input()
  b = input()

  if a/b == 0:
    print(a + b)
  else:
    print(b - a)

Buggy submission (verdict: Runtime Error):


a = input()
b = input()

if  a/b == 0:
  print(a + b)
else:
  print(b - a)
Problem p03126 (python)

Fixed submission:
N, M = map(int,input().split())
S = [0] * M
for i in range(N):
  A = list(map(int, input().split()))[1:]
  for j in A:
    S[j-1]+=1

count = 0
for y in S:
  if y == N:
    count+=1

print(count)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
S = [0] * M
for i in range(N):
  A = list(map(int, input().split()))[1:]
  for j in A:
    S[j]=S[j]+1
for y in S:
  if y == N:
    print(y)
Problem p03146 (python)

Fixed submission:
import collections
s = int(input())
result = [s]
tmp = s
while True:
  if collections.Counter(result).most_common()[0][1] == 2:
    break
  elif tmp%2 == 0:
    x = tmp/2
  elif tmp%2 > 0:
    x = (3*tmp) + 1
  tmp = x
  result.append(int(x))
print(len(result))

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

def collatz(s):
  if result[i-1] % 2 == 0:
    x = result[i-1]/2
  elif result[i-1] % 2 > 0:
    x = (3*int(result[i-1])) + 1
  return x

result = []
x = 0
c = 0
i = 0
tmp = []
while True:
  if i == 0:
    i += 1
    x = s
  elif c == 2:
    break
  elif int(x) == 1:
    i = 1
    c += 1
    x = result[i]
    continue
  else:
    x = collatz(s)
    i += 1
  result.append(int(x))
list_hoge = [i for i, x in enumerate(result) if x == result[1]]
print(sum(list_hoge))

Buggy submission (verdict: Runtime Error):
s = int(input())
result = [s]
tmp = s
while True:
  if tmp == 1:
    break
  elif tmp%2 == 0:
    x = tmp/2
  else:
    x = (3*tmp) + 1
  tmp = x
  result.append(int(x))
print(len(result+1))
Problem p03285 (python)

Fixed submission:
N = int(input())
multiple_4 = [x*4 for x in range(101) if x >= 1 and x <= 25]
multiple_7 = [x*7 for x in range(101) if x >= 1 and x <= 14]
multiple_4_7 = [x*4+7 for x in range(101) if x >= 1 and x <= 23]
multiple_7_4 = [x*7+4 for x in range(101) if x >= 1 and x <= 23]
tmp = []
for i in range(10):
  for j in range(10):
    solve = (4*(i+1))+(7*(j+1))
    if solve <= 100:
      tmp.append(solve)
multiple_other = sorted(list(set(tmp)))
if N in multiple_4 or N in multiple_7 or N in multiple_4_7 or N in multiple_7_4 or N in multiple_other:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
multiple_4 = [x*4 for x in range(101) if x >= 1 and x <= 25]
multiple_7 = [x*7 for x in range(101) if x >= 1 and x <= 14]
multiple_4_7 = [x*4+7 for x in range(101) if x >= 1 and x <= 23]
multiple_7_4 = [x*7+4 for x in range(101) if x >= 1 and x <= 23]
tmp = []
for i in range(10):
  for j in range(10):
    solve = (4*(i+1))+(7*(j+1))
    if solve <= 100:
      tmp.append(solve)
multiple_other = sorted(list(set(tmp)))
  if N in multiple_4 or N in multiple_7 or N in multiple_4_7 or N in multiple_7_4 or N in multiple_other:
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
multiple_4 = [x*4 for x in range(101) if x >= 1 and x <= 25]
multiple_7 = [x*7 for x in range(101) if x >= 1 and x <= 14]
multiple_4_7 = [x*4+7 for x in range(101) if x >= 1 and x <= 23]
multiple_7_4 = [x*7+4 for x in range(101) if x >= 1 and x <= 23]
if N in multiple_4 or N in multiple_7 or N in multiple_4_7 or N in multiple_7_4:
  print(N, "Yes")
  continue
else:
  print(N, "No")
  continue
Problem p03292 (python)

Fixed submission:
As = input().split()
result =  int(max(As)) - int(min(As))
print(-result if result<0 else result)

Buggy submission (verdict: Runtime Error):
As = input().split()
print(max(As)-min(As))
Problem p02588 (python)

Fixed submission:
import numpy as np

N = int(input())

A = []
for i in range(N):
    num = float(input()) * 10 ** 9 + 0.5
    A.append(int(num))


def count2(n):
    ret = 0
    while(n % 2 == 0):
        ret += 1
        n /= 2
    return ret


def count5(n):
    ret = 0
    while(n % 5 == 0):
        ret += 1
        n /= 5
    return ret


table = {}
for i in range(19):
    for j in range(19):
        table[i, j] = 0

for a in A:
    c2 = count2(a)
    c5 = count5(a)
    if(c2 > 18):
        c2 = 18
    if(c5 > 18):
        c5 = 18
    table[c2, c5] += 1

res = 0
for i in range(19):
    for j in range(19):
        for k in range(19):
            for l in range(19):
                if i + k >= 18 and j + l >= 18:
                    if i == k and j == l:
                        res += table[i, j] * (table[i, j] - 1)
                    else:
                        res += table[i, j] * table[k, l]

print(res // 2)

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

N = int(input())

A = []
for i in range(N):
    num = float(input()) * 10000
    if float.is_integer(num):
        A.append(int(num))


def count2(n):
    ret = 0
    while(n % 2 == 0):
        ret += 1
        n /= 2
    return ret


def count5(n):
    ret = 0
    while(n % 5 == 0):
        ret += 1
        n /= 5
    return ret


table = {}
for i in range(9):
    for j in range(9):
        table[i, j] = 0

for a in A:
    c2 = count2(a)
    c5 = count5(a)
    if(c2 > 8):
        c2 = 8
    if(c5 > 8):
        c5 = 8
    for i in range(c2 + 1):
        for j in range(c5 + 1):
            table[i, j] += 1

res = 0
for a in A:
    pair = count2(a), count5(a)
    t, f = pair
    res += table[8 - t, 8 - f]
    if t >= 4 and f >= 4:
        res -= 1

print(res // 2)
Problem p02945 (python)

Fixed submission:
a = list(map(int,input().split()))
A = a[0]
B = a[1]
list = []
list.append(A + B)
list.append(A - B)
list.append(A * B)
print(max(list))

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
list = []
list.append(A + B)
list.append(A - B)
list.append(A * B)
print(max(list))
Problem p02946 (python)

Fixed submission:
a = list(map(int,input().split()))
K = a[0]
X = a[1]
m = X - K + 1
M = X + K - 1
size = M - m + 1
while m <= M:
  print(m)
  m += 1

Buggy submission (verdict: Runtime Error):
a = list(map(int,input().split()))
K = a[0]
X = a[1]
m = X - K
M = x + K
size = M - m + 1
for i in range(size):
  print(m+i)
Problem p02554 (python)

Fixed submission:
import numpy as np

n = int(input())
MOD = 1000000007
ans = 10**n - 9**n -9**n + 8**n
ans = ans % MOD
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = pow(10,n,mod)
ans -= pow(9,n,mod)*2
ans += pow(8,n,mod)
print(ans%mod)

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

N = int(input())
MOD = 1000000007
if N==1 or N==0:
    ans=0

elif N==2:
    ans =2

else:
    ans = (  ( N*(N-1) ) %MOD  ) * (  (  10**(N-2) - (N-2)*(N-3)/2   )%MOD)
    ans = ans % MOD

print(ans)
Problem p02641 (python)

Fixed submission:
import numpy as np
X,N = map(int,input().split())

if N ==0:
    print(X)

else:
    p = list(map(int,input().split()))

    length =np.zeros(102)
    length =list(length)

    for i in range(len(length)):
        length[i]= abs(X-i)

    for i in range(N):
        length[p[i]]=1000

    ans = length.index(min(length))
    print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
X,N = map(int,input().split())

if N ==0:
    print(X)

else:
    p = list(map(int,input().split()))

    length =np.zeros(100)
    length =list(length)

    for i in range(len(length)):
        length[i]= abs(X-i)

    for i in range(N):
        length[p[i]]=1000

    ans = length.index(min(length))
    print(ans)
Problem p02717 (python)

Fixed submission:
X,Y,Z = list(map(int, input().split(" ")))
print(str(Z) + " " + str(X) + " " + str(Y))

Buggy submission (verdict: Runtime Error):
X,Y,Z = list(map(int, input().split(" ")))
print(Z + " " + X + " " + Y)
Problem p02732 (python)

Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split(" ")))
m = Counter(A)
def nck(n, k): 
    C = [[0 for x in range(k+1)] for x in range(n+1)] 
  
    # Calculate value of Binomial Coefficient in bottom up manner 
    for i in range(n+1): 
        for j in range(min(i, k)+1): 
            # Base Cases 
            if j == 0 or j == i: 
                C[i][j] = 1
  
            # Calculate value using previously stored values 
            else: 
                C[i][j] = C[i-1][j-1] + C[i-1][j] 
  
    return C

most_common,num_most_common = m.most_common(1)[0]
CHOOSE_MATRIX = nck(num_most_common, 2)
total = 0
for key, value in m.items():
        # if key == A[i]:
        #     continue
        # else:
    total += CHOOSE_MATRIX[value][2]


for i in range(len(A)):
    newtotal = total
    # m[A[i]] -= 1
    # for key, value in m.items():
    #     # if key == A[i]:
    #     #     continue
    #     # else:
    #     total += CHOOSE_MATRIX[value][2]
    # m[A[i]] += 1
    tosubtract = CHOOSE_MATRIX[m[A[i]]][2]
    newtotal -= tosubtract
    newtotal += CHOOSE_MATRIX[m[A[i]]- 1][2]
    print(newtotal)
    # print(uniquethings*(uniquethings)//2)
    # print(total)

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

N = int(input())
A = list(map(int, input().split(" ")))
m = Counter(A)
def nck(n, k): 
    C = [[0 for x in range(k+1)] for x in range(n+1)] 
  
    # Calculate value of Binomial Coefficient in bottom up manner 
    for i in range(n+1): 
        for j in range(min(i, k)+1): 
            # Base Cases 
            if j == 0 or j == i: 
                C[i][j] = 1
  
            # Calculate value using previously stored values 
            else: 
                C[i][j] = C[i-1][j-1] + C[i-1][j] 
  
    return C

CHOOSE_MATRIX = nck(max(A) + 1, 2)
total = 0
for key, value in m.items():
        # if key == A[i]:
        #     continue
        # else:
        total += CHOOSE_MATRIX[value][2]


for i in range(len(A)):
    newtotal = total
    # m[A[i]] -= 1
    # for key, value in m.items():
    #     # if key == A[i]:
    #     #     continue
    #     # else:
    #     total += CHOOSE_MATRIX[value][2]
    # m[A[i]] += 1
    tosubtract = CHOOSE_MATRIX[m[A[i]]][2]
    newtotal -= tosubtract
    newtotal += CHOOSE_MATRIX[m[A[i]]- 1][2]
    print(newtotal)
    # print(uniquethings*(uniquethings)//2)
    # print(total)

Buggy submission (verdict: Runtime Error):


from collections import Counter
N = int(input())
A = list(map(int, input().split(" ")))
def nck(n, k):
    if k > n:
        return 0
    else:
        return factorial(n)//(factorial(n-k)*factorial(k))

def factorial(n):

    if n<= 1:
        return 1
    else:
        return n*factorial(n-1)


for i in range(len(A)):
    total =0
    m = Counter(A[:i] + A[i+1:])
    for key, value in m.items():
        total += nck(value, 2)

    # print(uniquethings*(uniquethings)//2)
    print(total)
Problem p02817 (python)

Fixed submission:
string_list = input()
string_list =  list(map(str, string_list.split(" ")))
print(string_list[1] + string_list[0])

Buggy submission (verdict: Runtime Error):
string_list = map(str, input().split(" "))
print(string_list[1] + string_list[0])
Problem p03162 (python)

Fixed submission:
N = int(input())
dp = [[0]*3 for _ in range(N+1)]
happy = [[0]*3 for _ in range(N)]

for i in range(N):
    a, b, c = [int(s) for s in input().split()]
    happy[i][0] = a
    happy[i][1] = b
    happy[i][2] = c

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j!= k:
                dp[i+1][k] = max(dp[i+1][k], dp[i][j] + happy[i][j])

ans = max(dp[N][0],dp[N][1],dp[N][2])
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
dp = [[0]*(N+1) for _ in range(3)]
happy = [[0]*N for _ in range(3)]

for i in range(N):
    a, b, c = [int(s) for s in input().split()]
    happy[i][0] = a
    happy[i][1] = b
    happy[i][2] = c

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j!= k:
                dp[i+1][j] = max(dp[i+1][j], dp[i][j] + happy[i][k])

ans = max(dp[N][0],dp[N][1],dp[N][2])
print(ans)
Problem p03164 (python)

Fixed submission:
N,W = [int(s) for s in input().split()]
dp = [[10**10]*(1000*100+1) for _ in range(N+1)]#外側から内側のイメージ

dp[0][0] = 0
for i in range(N):
    w, v = [int(s) for s in input().split()]
    for sum_v in range(1000*100+1):
        if sum_v - v >= 0:
            dp[i+1][sum_v] = min(dp[i][sum_v], dp[i][sum_v-v] + w)
        else:
            dp[i+1][sum_v] = dp[i][sum_v]

ans = 0
for sum_v in range(1000*100+1):
    if dp[N][sum_v] <= W:
        ans = sum_v

print(ans)

Buggy submission (verdict: Runtime Error):
N,W = [int(s) for s in input().split()]
dp = [[10**10]*(1001) for _ in range(N+1)]#外側から内側のイメージ

dp[0][0] = 0
for i in range(N):
    w, v = [int(s) for s in input().split()]
    for sum_v in range(1000*100):
        if sum_v - v >= 0:
            dp[i+1][sum_v] = min(dp[i][sum_v], dp[i][sum_v-v] + w)
        else:
            dp[i+1][sum_v] = dp[i][sum_v]

ans = 0
for sum_v in range(1000*100):
    if dp[N][sum_v] <= W:
        ans = sum_v

print(ans)
Problem p03166 (python)

Fixed submission:
import sys

N, M = [int(s) for s in input().split()]
sys.setrecursionlimit(10**5)
dp = [-1] * (N+1)
neighbors = [[] for _ in range(N+1)]

for _ in range(M):
    x, y = [int(s) for s in input().split()]
    neighbors[x].append(y)

def LP(v):
    if dp[v] != -1:
        return dp[v]
    else:
        res = 0
        lp = [-1]
        for nv in neighbors[v]:
            lp.append(LP(nv))
        res = max(res, max(lp) + 1)
        dp[v] = res
        return res

ans = 0
for v in range(1,N+1):
    ans = max(ans, LP(v))

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

N, M = [int(s) for s in input().split()]
sys.setrecursionlimit(N)
dp = [-1] * (N+1)
neighbors = [[] for _ in range(N+1)]

for _ in range(M):
    x, y = [int(s) for s in input().split()]
    neighbors[x].append(y)

def LP(v):
    if dp[v] != -1:
        return dp[v]
    else:
        res = 0
        lp = [-1]
        for nv in neighbors[v]:
            lp.append(LP(nv))
        res = max(res, max(lp) + 1)
        dp[v] = res
        return res

ans = 0
for v in range(1,N+1):
    ans = max(ans, LP(v))

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = [int(s) for s in input().split()]

dp = [-1] * (N+1)
neighbors = [[] for _ in range(N+1)]

for _ in range(M):
    x, y = [int(s) for s in input().split()]
    neighbors[x].append(y)

def LP(v):
    if dp[v] != -1:
        return dp[v]
    else:
        res = 0
        lp = [-1]
        for nv in neighbors[v]:
            lp.append(LP(nv))
        res = max(res, max(lp) + 1)
        dp[v] = res
        return res

ans = 0
for v in range(1,N+1):
    ans = max(ans, LP(v))

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = [int(s) for s in input().split()]

dp = [-1] * (N+1)
neighbors = [[] for _ in range(1,N+1)]

for _ in range(M):
    x, y = [int(s) for s in input().split()]
    neighbors[x].append(y)

def LP(v):
    if dp[v] != -1:
        return dp[v]
    else:
        res = 0
        lp = []
        for nv in neighbors[v]:
            lp.append(LP(nv))
        res = max(res, max(lp) + 1)
        dp[v] = res
        return res

ans = 0
for v in range(1,N+1):
    ans = max(ans, LP(v))

print(ans)
Problem p03354 (python)

Fixed submission:
N,M = [int(s) for s in input().split()]
p = [0] + [int(s) for s in input().split()]
par = []
counter = 0

for i in range(N+1):
    par.append(i)
    
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def same(x,y):
    return find(x) == find(y)

def union(x,y):
    x = find(x)
    y = find(y)
    if x != y:
        par[x] = y

for i in range(M):
    x,y = [int(s) for s in input().split()]
    union(x,y)
    
for i in range(1,N+1):
    if same(i,p[i]):
        counter += 1

print(counter)

Buggy submission (verdict: Runtime Error):
N,M = [int(s) for s in input().split()]
p = [int(s) for s in input().split()]
par = []
counter = 0

for i in range(N):
    par.append(i+1)
    
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def same(x,y):
    return find(x) == find(y):

def union(x,y):
    x = find(x)
    y = find(y)
    if x != y:
        par[x] = y

for i in range(M):
    x,y = [int(s) for s in input().split()]
    union(x,y)
    
for i in range(N):
    if same(i+1,p[i]):
        counter += 1

print(counter)
Problem p03471 (python)

Fixed submission:
h = [int(s) for s in input().split()]
N = h[0]
Y = h[1]

def otoshidama(N,Y):
	ok_flag = 0
	money = 0
	for i in range(N+1):
		for j in range(N+1-i):
			money = 10000*i + 5000*j + 1000*(N-i-j)
			if money == Y:
				print(i,j,N-i-j)
				ok_flag = 1
				return
			money = 0
		money = 0
	if ok_flag == 0:
		print(-1,-1,-1)
  
otoshidama(N,Y)

Buggy submission (verdict: Runtime Error):
h = [int(s) for s in input().split()]
N = h[0]
Y = h[1]

def otoshidama(a,b):
	ok_flag = 0
	money = 0
	for i in range(N+1):
  		for j in range(N+1-i):
      		money = 10000*i + 5000*j + 1000*(N-i-j)
      		if money == Y:
        		print(i,j,N-i-j)
        		ok_flag = 1
        		return
      		money = 0 
	if ok_flag == 0:
  		print(-1 -1 -1)
  
otoshidama(N,Y)