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

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

if (A+B)%2==1:
  print("IMPOSSIBLE")
  
else:
  print((A+B)//2)

Buggy submission (verdict: Runtime Error):
A,B=map(int,input.split())

if (A+B)%2==1:
  print("IMPOSSIBLE")
  
else:
  print((A+B)//2)

Buggy submission (verdict: Runtime Error):
A,B=map(int(input.split()))

if (A+B)%2==1:
  print("IMPOSSIBLE")
  
else:
  print((A+B)/2)
Problem p02975 (python)

Fixed submission:
import collections
N = int(input())
a = list(map(int, input().split()))
A = set()
table = collections.defaultdict(int)

for i in range(1, N):
    table[a[i]] += 1

ans = [-1]*N
ans[0] = a[0]
for i in range(1, N):
    if (a[0] ^ a[i]) in table and table[a[0] ^ a[i]] >= 1:
        if a[0] == 0:
            if table[a[i]] == 1:
                continue
        ans[1] = (a[0] ^ a[i])
        ans[2] = a[i]
        table[ans[1]] -= 1
        table[ans[2]] -= 1
        break

if ans[1] == -1:
    print("No")
    exit(0)

for i in range(3, N):
    if (ans[i-1] ^ ans[i-2]) in table and table[ans[i-1] ^ ans[i-2]] >= 1 and table[ans[i-1] ^ ans[i-2]] >= 1:

        ans[i] = ans[i-1] ^ ans[i-2]
        table[ans[i]] -= 1
    else:
        print("No")
        exit(0)
print("Yes")

Buggy submission (verdict: Runtime Error):
import collections
N = int(input())
a = list(map(int, input().split()))
A = set()
table = collections.defaultdict(int)

for i in range(1, N):
    table[a[i]] = i

ans = [-1]*N
ans[0] = a[0]
for i in range(1, N):
    if (a[0] ^ a[i]) in table and table[a[0] ^ a[i]] != i:
        ans[1] = a[0] ^ a[i]
        ans[2] = a[i]
        del(table[ans[1]])
        del(table[ans[2]])
        break
if ans[1] == -1:
    print("No")
    exit(0)

for i in range(3, N):
    if (ans[i-1] ^ ans[i-2]) in table and table[ans[i-1] ^ ans[i-2]] != i-2 and table[ans[i-1] ^ ans[i-2]] != i-1:
        ans[i] = ans[i-1] ^ ans[i-2]
        del(table[ans[i]])
    else:
        print("No")
        exit(0)
print("Yes")

Buggy submission (verdict: Runtime Error):
import collections
N = int(input())
a = list(map(int, input().split()))
A = set()
table = collections.defaultdict(int)
for i in range(1, N):
    table[a[i]] += 2
a.sort()
prev = a[0]
now = a[0]
last = a[0]
for i in range(1, N):
    if (a[0] ^ a[i]) in table and table[a[0] ^ a[i]] > 0:
        table[a[0] ^ a[i]] -= 1
        last = a[i]
        now = a[0] | a[i]
        break
	if i == N-1:
      print("No")
      exit(0)
for i in range(2, N-2):
    if prev ^ now in table and table[now ^ prev] > 0:
        prev = now
        now = now ^ prev
        table[now ^ prev] -= 1
    else:
        print("No")
        exit(0)
if (last ^ now) == a[0]:
    print("Yes")
else:
    print("No")
Problem p02981 (python)

Fixed submission:
N,A,B=map(int,input().split())
print(min(N*A,B))

Buggy submission (verdict: Runtime Error):
N,A,B=map(input().split())
print(max(N*A,B))
Problem p02982 (python)

Fixed submission:
import math
N,D=map(int,input().split())
X=[0]*N
for i in range(N):
  X[i]=list(map(int,input().split()))
count=0
for i in range(N):
  for j in range(i,N):
    dis=0
    for k in range(D):
      dis += pow(X[i][k]-X[j][k],2) 
    dis = math.sqrt(dis)

    if dis==int(dis) and dis!=0:
      count+=1
print(count)

Buggy submission (verdict: Runtime Error):
N,D=map(int,input().split())
for i in range(N):
  X[i]=list(map(int,input().split()))
count=0
for i in range(N):
  for j in range(i,N):
    dis=0
    for k in range(D):
      dis += pow(X[i][k],2) + pow(X[j][k],2) 
    dis = sqrt(dis)
    if dis==int(dis):
      count+=1
print(count)
Problem p02983 (python)

Fixed submission:
L,R = map(int,input().split())
ans = 2019

if R*(R-1)<2019:
  print(R*(R-1))
  exit(0)
else:
  if R == L+1:
    print((R*L)%2019)
    exit(0)
  else:
    r =673 - L % 673
    if L+r <= R:
      print("0")
      exit(0)
    else:
      for i in range(L,R+1):
        for j in range(i+1,R+1):
          if (i*j)%2019 < ans:
            ans = (i*j) % 2019
            if ans == 0:
              break
print(ans)

Buggy submission (verdict: Runtime Error):
L,R = map(int,input().split())
ans = 2019
for i in range(L,R+1):
  for j in range(i,R+1):
    if (i*j)%2019 < ans:
      ans = (i*J) % 2019
      if ans == 0:
        break
print(ans)
Problem p02985 (python)

Fixed submission:
import collections
N,K=map(int,input().split())
G=[set() for i in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  G[a].add(b)
  G[b].add(a)
m=0
id=9
for i in range(N):
  if len(G[i])>m:
    id=i
    m = len(G[i])
q=collections.deque()
q.append(0)
colored=[False]*N
colored[0]=True
from math import factorial
mod = 10**9 + 7
ans = K
while(q):
  x= q.popleft()
  count=0
  for y in G[x]:
    if colored[y]:
      continue
    else:
      q.append(y)
      colored[y]=True
      count+=1
      
  for i in range(count):
    ans *= K-1-(len(G[x])-count)-i
    ans %= mod
  #print(ans,count,factorial(K-1-(len(G[x])-count)),factorial(count))
print(ans)

Buggy submission (verdict: Runtime Error):
import fractions
import collections
N, K = map(int, input().split())
G = [set() for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].add(b)
    G[b].add(a)

q = collections.deque()
q.append((0))
ans = K
mod = 10**9+7
r = [True]*N
r[0] = False
while(q):
    x = q.popleft()
    tmp = K - 1
    if x > 0:
        tmp -= 1
    for y in G[x]:
        if r[y]:
            r[y] = False
            q.append(y)
            ans *= tmp
            tmp -= 1
    		ans %= mod
print(ans)
Problem p02993 (python)

Fixed submission:
S=input()
for i in range(3):
  if S[i]==S[i+1]:
    print("Bad")
    exit(0)
print("Good")

Buggy submission (verdict: Runtime Error):
N,L=map(int,input().split())
if L >= 0:
  print(int((N-1)/2*(L + L + N)))
else:
  if L + N - 1 >= 0: 
    print(int(N / 2 * (L + L + N - 1)))
  else:
    print(int((N - 1)/ 2 * (L + L + N - 2)))
Problem p02994 (python)

Fixed submission:
N,L=map(int,input().split())
if L >= 0:
  print(int((N-1)/2*(L + L + N)))
else:
  if L + N - 1 >= 0: 
    print(int(N / 2 * (L + L + N - 1)))
  else:
    print(int((N - 1)/ 2 * (L + L + N - 2)))

Buggy submission (verdict: Runtime Error):
(int,input().split())
if L >= 0:
  print(int((N-1)/2*(L + L + N )))
else:
  if L + N - 1 >= 0: 
    print(int(N / 2 * (L + L + N - 1)))
  else:
    print(int((N - 1)/ 2 * (L + L + N - 2)))

Buggy submission (verdict: Runtime Error):
N,L=(int,input().split())
if L >= 0:
  print(int((N-1)/2*(L + L + N - 1)))
else:
  if L + N - 1 >= 0: 
    print(int(N / 2 * (L + L + N - 1)))
  else:
    print(int((N - 1)/ 2 * (L + L + N - 2)))
Problem p02995 (python)

Fixed submission:
import fractions
A,B,C,D = map(int,input().split())

lcm = int(C*D / fractions.gcd(C,D))
ans_b = B - (B // C) - (B // D) + (B // lcm)
ans_a = A - 1 - ((A - 1)// C) - ((A - 1)// D) + ((A - 1) // lcm)

print(int(ans_b - ans_a))

Buggy submission (verdict: Runtime Error):
import fractions
A,B,C,D = map(int,input().split())

icm = C*D / fractions.gcd(C,D)
ans = (B - A + 1)
if A != B:
    if A % C == 0:
        ans -= int(B // C - A // C) + 1
    else:
        ans -= int(B // C - A // C)
    if A % D == 0:
        ans -= int(B // D - A // D) + 1
    else:
        ans -= int(B // D - A // D)

    if A % icm == 0:
        ans += int(B // icm - A // icm) + 1
    else:
        ans += int(B // icm - A // icm)
	print(int(ans))
else:
    if A % C == 0 or A % D == 0:
        print(0)
    else:
        print(1)

Buggy submission (verdict: Runtime Error):
import math
A,B,C,D = map(int,input().split())

icm = C*D / math.gcd(C,D)
ans = (B - A + 1)
if A % C == 0:
    ans -= (B // C - A // C) - 1
else:
    ans -= (B // C - A // C)
if A % D == 0:
    ans -= (B // D - A // D) - 1
else:
    ans -= (B // D - A // D)

if A % icm == 0:
    ans += (B // icm - A // icm) - 1
else:
    ans += (B // icm - A // icm)

print(int(ans))
Problem p02999 (python)

Fixed submission:
X,A=map(int,input().split())
if X < A:
  print('0')
else:
  print('10')

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

D=[0]*(N)

D[0]=0
count=1
for i in range(1,N):
  D[i]=D[i-1]+L[i-1]
  if D[i]<=X:
    count+=1
  else:
    break
print(count)
Problem p03000 (python)

Fixed submission:
N,X=map(int,input().split())
L=list(map(int,input().split()))

D=[0]*(N+1)

D[0]=0
count=1
for i in range(1,N+1):
  D[i]=D[i-1]+L[i-1]
  if D[i]<=X:
    count+=1
  else:
    break
print(count)

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

D=[0]*(N-1)

D[0]=0
count=1
for i in range(1,N):
  D[i]=D[i-1]+L[i-1]
  if D[i]<=X:
    count+=1
  else:
    break
print(count)
Problem p03026 (python)

Fixed submission:
import heapq
import sys
sys.setrecursionlimit(20000)
N = int(input())
ab = [tuple(map(int, input().split())) for i in range(N-1)]
c = list(map(int, input().split()))

print(sum(c) - max(c))
c = list(map(lambda x: x*(-1), c))
heapq.heapify(c)
d = [[0, i] for i in range(N)]
g = [set() for i in range(N)]
for a, b in ab:
    d[a-1][0] += 1
    d[b-1][0] += 1
    g[a-1].add(b-1)
    g[b-1].add(a-1)
d.sort(reverse=True, key=lambda x: x[0])
for i in range(N):
    d[i][0] = -1


ans = ["-1"]*N
ans[d[0][1]] = str(-1 * heapq.heappop(c))


def dfs(start):
    for x in g[start]:
        if ans[x] == "-1":
            ans[x] = str(-1 * heapq.heappop(c))
            dfs(x)


dfs(d[0][1])
d.sort(key=lambda x: x[1])


print(" ".join(ans))

Buggy submission (verdict: Runtime Error):
import heapq
N = int(input())
ab = [tuple(map(int, input().split())) for i in range(N-1)]
c = list(map(int, input().split()))

print(sum(c) - max(c))
c = list(map(lambda x: x*(-1), c))
heapq.heapify(c)
d = [[0, i] for i in range(N)]
g = [set() for i in range(N)]
for a, b in ab:
    d[a-1][0] += 1
    d[b-1][0] += 1
    g[a-1].add(b-1)
    g[b-1].add(a-1)
d.sort(reverse=True, key=lambda x: x[0])
for i in range(N):
    d[i][0] = -1
d[0][0] = -1 * heapq.heappop(c)


def dfs(start):
    for x in g[start]:

        if d[x][0] == -1:

            d[x][0] = d[x][0] * heapq.heappop(c)

            dfs(x)


dfs(0)
d.sort(key=lambda x: x[1])

ans = [""]*N
for i in range(N):
    ans[i] = str(d[i][0])
print(" ".join(ans))
Problem p03032 (python)

Fixed submission:
import heapq
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for k in range(min(K+1, N+1)):
    for i in range(k+1):
        tmp = 0
        tmp2 = []
        heapq.heapify(tmp2)

        for j in range(k-i):
            tmp += V[j]
            if V[j] < 0:
                heapq.heappush(tmp2, V[j])
        for j in range(i):
            tmp += V[N-1-j]
            if V[N-1-j] < 0:

                heapq.heappush(tmp2, V[N-1-j])

        for j in range(min(k, K-k)):
            if len(tmp2) == 0:
                break
            tmp -= heapq.heappop(tmp2)
        ans = max(tmp, ans)


print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for k in range(K+1):
    for i in range(k+1):
        tmp = 0
        tmp2 = []
        heapq.heapify(tmp2)

        for j in range(k-i):
            tmp += V[j]
            if V[j] < 0:
                heapq.heappush(tmp2, V[j])
        for j in range(i):
            tmp += V[N-1-j]
            if V[N-1-j] < 0:

                heapq.heappush(tmp2, V[N-1-j])

        for j in range(min(k, K-k)):
            if len(tmp2) == 0:
                break
            tmp -= heapq.heappop(tmp2)
        ans = max(tmp, ans)


print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for k in range(K+1):
    for i in range(k+1):
        tmp = 0
        tmp2 = []
        heapq.heapify(tmp2)

        for j in range(k-i):
            tmp += V[j]
            if V[j] < 0:
                heapq.heappush(tmp2, V[j])
        for j in range(i):
            tmp += V[j]
            if V[N-1-j] < 0:

                heapq.heappush(tmp2, V[j])

        for j in range(min(k, K-k)):
            tmp -= heapq.heappop(tmp2)
        ans = max(tmp, ans)


print(ans)
Problem p03037 (python)

Fixed submission:
N,M=map(int,input().split())
L=[-1]*M
R=[-1]*M
for i in range(M):
  L[i],R[i] =map(int,input().split())
if min(R) >= max(L):
  print(min(R)-max(L)+1)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
L=[-1]*M
R=[-1]*M
for i in range(M):
  L[i],R[i] =map(input().split())
  
print(min(R)-max(L)+1)
Problem p03048 (python)

Fixed submission:
R,G,B,N=map(int,input().split())
ans=0
for i in range(N//R + 1):
  for j in range(N//G + 1):
    if R*i+G*j <= N:
      if (N - (R*i+G*j))%B==0:
        ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
R,G,B,N=map(int,input().split())
ans=0
for i in range(N//R + 1):
  for j in range(N//G + 1)
  if R*i+G*j <= N:
    if (N - (R*i+G*j))%B==0:
      ans+=1
print(ans)
Problem p03050 (python)

Fixed submission:
N = int(input())
ans = 0
for i in range(1, int(N**0.5)+1):
    if N // i > 1:
        if i == N % (N//i - 1):
            ans += N//i - 1

print(ans)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
ans = 0
for i in range(1, int(N**0.5)+1):
    if i == N % (N//i - 1):
        ans += N//i - 1

print(ans)
Problem p03062 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
count = 0
A.sort(key=lambda x: abs(x))
for x in A:
    if x < 0:
        count += 1
A = [abs(x) for x in A]
ans = 0
if count % 2 == 0:
    ans = sum(A)
else:
    ans = sum(A[1:]) - A[0]

print(ans)

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

if abs(A[0]) < abs(A[-1]):
    A = A[::-1]
B = list(map(abs, A))
tmp = A[0] // abs(A[0])
for i in range(1, N):
    if A[i] == 0:
        tmp = 0
        continue
    if tmp < 0:
        tmp = tmp*(A[i] // abs(A[i]))
    else:
        tmp = A[i] // abs(A[i])

if tmp < 0:
    print(sum(B) - 2 * B[-1])
else:
    print(sum(B))
Problem p03071 (python)

Fixed submission:
A,B = map(int, input().split())
ans = 0
for i in range(2):
    if A > B:
        ans += A
        A = A - 1
    else:
        ans += B
        B = B - 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
for i in range(N):
    if V[i] - C[i] > 0:
        ans += V[i] - C[i]

print(ans)
Problem p03076 (python)

Fixed submission:
def int_ceil(x):
  last=int(str(x)[-1])
  return([x+10-last,last])

dishes =[0]*5
min=10
for i in range(5):
  x=(int(input()))
  if x % 10 != 0:
    ceiled=int_ceil(x)
    if ceiled[1] < min:
      min=ceiled[1]
    dishes[i]=ceiled[0]
  else:
    dishes[i]=x
print(sum(dishes) - 10 + min)

Buggy submission (verdict: Runtime Error):
import math
dishes =[0]*5
for i in range(5):
  dishes[i]=math.celi(int(input()))

print(sum(dishes))
Problem p03085 (python)

Fixed submission:
b=input()
if b == "A":
  print("T")
elif b == "G":
  print("C")
elif b == "T":
  print("A")
elif b == "C":
  print("G")

Buggy submission (verdict: Runtime Error):
b=input()
if b = "A":
  print("T")
elif b = "G":
  print("C")
elif b = "T":
  print("A")
elif b = "C":
  print("G")
Problem p03096 (python)

Fixed submission:
import sys
input=sys.stdin.readline
N=int(input())
C=[int(input())]
for i in range(N-1):
  tmp=int(input())
  if tmp != C[-1]:
    C.append(tmp)
  
import collections
table=collections.defaultdict(int)
N=len(C)
dp=[0]*(N+1)
dp[N]=1
mod=10**9 + 7
for i,x in enumerate(C[::-1]):
  dp[N-1-i]=dp[N-i] + table[x] 
  dp[N-1-i]%=mod
  table[x]+=dp[N-i]
print(dp[0])

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
N=int(input())
C=[int(input())]
for i in range(N-1):
  tmp=int(input())
  if tmp != C[-1]:
    C.append(tmp)
  
import collections
table=collections.defaultdict(int)
N=len(C)
dp=[0]*(N+1)
dp[N]=1
mod=10**9 + 7
for i,x in enumerate(C[::-1]):
  dp[N-1-i]=dp[N-i] + table[x]
  
  dp[N-1-i]%=mod
  table[x]+=d[N-1-i]

print(dp[0])

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
N=int(input())
C=[int(input())]
for i in range(N-1)
  tmp=int(input())
  if tmp != C[-1]:
    C.append(tmp)
  
import collections
table=collections.defaultdict(list)
N=len(C)
dp=[0]*(N+1)
dp[N]=1
mod=10**9 + 7
for i,x in enumerate(C[::-1]):
  dp[N-1-i]=dp[N-i]
  for y in table[x]:
    dp[N-1-i]+=dp[y+1]
  dp[N-1-i]%=mod
  table[x].append(N-1-i)

print(dp[0])
Problem p03126 (python)

Fixed submission:
import collections
N,M=map(int,input().split())

counter=collections.defaultdict(int)
for _ in range(N):
  text = list(input().split())
  for x in text[1:]:
    counter[x]+=1
ans=0
for x in counter:
  if counter[x]== N:
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import collections
N,M=map(int,input().split())

counter=collections.defaultdict
for _ in range(N):
  text = list(input().split())
  for x in text[1:]:
    counter[x]+=1
ans=0
for _ in counter:
  if counter[x]== N:
    ans+=1
print(ans)
Problem p03141 (python)

Fixed submission:
N=int(input())
C=[list(map(int,input().split())) for i in range(N)]
C.sort(key=lambda x:sum(x), reverse=True)
ans=0
for i in range(N):
  if i%2==0:
    ans+=C[i][0]
  else:
    ans-=C[i][1]
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input().split())
C=[list(map(int,input().split())) for i in range(N)]
C.sort(key=lambda x:sum(x), reverse=True)
ans=0
for i in range(N):
  if i%2==0:
    ans+=C[i][0]
  else:
    ans-=C[i][1]
print(ans)
Problem p03146 (python)

Fixed submission:
import collections
s=int(input())
count=1
ans=s
prev=0
counter = collections.defaultdict(int)
counter[ans]=1
while(1):
  count+=1
  if ans % 2 == 0:
    ans = ans / 2
  else:
    ans = 3*ans+1
    
  if ans not in counter.keys():
    counter[ans]=count
  else:
    print(count)
    break

Buggy submission (verdict: Runtime Error):
import collections
s=int(input())
count=1
ans=s
prev=0
counter = collections.defaultdict(int)
counter[ans]=1
while(1):
  count+=1
  if ans % 2 == 0:
    ans = ans / 2
  else:
    ans = 3*n+1
    
  if ans not in counter.keys:
    counter[ans]=count
  else:
    print(counter[ans])
    break
Problem p03151 (python)

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

diff=[[A[i]-B[i],i] for i in range(N)]
diff=sorted(diff,key=lambda x:x[0])

idx=-1
for i in range(N):
  while(diff[i][0]<0):
    if diff[idx][0]< 0:
      print("-1")
      exit(0)
    if abs(diff[i][0]) >= diff[idx][0]:
      diff[i][0]+=diff[idx][0]
      diff[idx][0]=0
      idx-=1
    else:
      diff[idx][0]+=diff[i][0]
      diff[i][0]=0
diff=sorted(diff,key=lambda x:x[1])
C=[B[i]+diff[i][0] for i in range(N)]
ans=0
for i in range(N):
  if A[i]!=C[i]:
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(input().split())
B=list(input().split())

diff=[A[i]-B[i] for i in range(N)]
diff=sorted(diff)

idx=-1
for i in range(N):
  while(diff[i]<0):
    if diff[idx]< 0:
      print("-1")
      exit(0)
    if abs(diff[i]) >= diff[idx]:
      diff[i]+=diff[idx]
      diff[idx]=0
      idx-=1
    else:
      diff[idx]+=diff[i]
      diff[i]=0
      
C=[B[i]+diff[i] for i in range(N)]
ans=0
for i in range(N):
  if A[i]!=C[i]:
    ans+=1
print(ans)
Problem p03161 (python)

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

h = list(map(int, input().split()))

dp = [N * (10**4)]*N
dp[0] = 0


for i in range(N-1):
    for j in range(1, K+1):
        if i + j < N:
            dp[i+j] = min(dp[i] + abs(h[i+j] - h[i]), dp[i+j])
print(dp[N-1])

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

h = list(map(int, input().split()))

dp = [-1]*N
dp[0] = 0


def solve(n):
    if dp[n] != -1:
        return dp[n]
    ret = 2 * (10**4)
    for i in range(max(0, n-K), n):
        tmp = solve(i) + abs(h[i] - h[n])
        ret = min(tmp, ret)
    dp[n] = ret
    return dp[n]


print(solve(N-1))
Problem p03166 (python)

Fixed submission:
import collections
import sys
sys.setrecursionlimit(10**5)
N, M = map(int, input().split())
G = [set() for i in range(N)]
L = [-1]*N


def solve(x, r):
    if L[x] >= 0:
        return(L[x])
    res = 0
    for z in G[x]:
        if r[z]:
            r[z] = False
            res = max(res, solve(z, r) + 1)
        else:
            res = max(res, L[z]+1)
    L[x] = res
    return(res)


for i in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1

    G[x].add(y)

r = [True]*N

for i in range(N):
    # print(L)
    if r[i]:
        L[i] = solve(i, r)
print(max(L))

# print(L)

Buggy submission (verdict: Runtime Error):
import collections
N, M = map(int, input().split())
G = [set() for i in range(N)]
L = [-1]*N


def solve(x, r):
    if L[x] >= 0:
        return(L[x])
    res = 0
    for z in G[x]:
        if r[z]:
            r[z] = False
            res = max(res, solve(z, r) + 1)
        else:
            res = max(res, L[z]+1)
    L[x] = res
    return(res)


for i in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1

    G[x].add(y)

r = [True]*N

for i in range(N):
    # print(L)
    if r[i]:
        L[i] = solve(i, r)
print(max(L))

# print(L)
Problem p03169 (python)

Fixed submission:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    a = A.count(1)
    b = A.count(2)
    c = A.count(3)
    floatN = N*1.0
    dp = [[[.0]*(N+1) for i in range(N+1)] for j in range(N+1)]

    for k in range(c+1):
        for j in range(b+c + 1 - k):
            for i in range(N + 1 - k - j):
                if i + j+k == 0:
                    continue
                dp[i][j][k] = floatN
                if i > 0:
                    dp[i][j][k] += dp[i-1][j][k] * i
                if j > 0:
                    dp[i][j][k] += dp[i+1][j-1][k] * j
                if k > 0:
                    dp[i][j][k] += dp[i][j+1][k-1] * k
                dp[i][j][k] /= (i+j+k)
    print(dp[a][b][c])


main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    a = A.count(1)
    b = A.count(2)
    c = A.count(3)
    floatN = N*1.0
    dp = [[[0]*(N+1) for i in range(N+1)] for j in range(N+1)]

    for k in range(A[3]+1):
        for j in range(A[2]+A[3] + 1 - k):
            for i in range(N + 1 - k - j):
                if i + j+k == 0:
                    continue
                dp[i][j][k] = floatN
                if i > 0:
                    dp[i][j][k] += dp[i-1][j][k] * i
                if j > 0:
                    dp[i][j][k] += dp[i+1][j-1][k] * j
                if k > 0:
                    dp[i][j][k] += dp[i][j+1][k-1] * k
                dp[i][j][k] /= (i+j+k)
    print(dp[a][b][c])


main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    a = A.count(1)
    b = A.count(2)
    c = A.count(3)]
    floatN = N*1.0
    dp = [[[0]*(N+1) for i in range(N+1)] for j in range(N+1)]

    for k in range(A[3]+1):
        for j in range(A[2]+A[3] + 1 - k):
            for i in range(N + 1 - k - j):
                if i + j+k == 0:
                    continue
                dp[i][j][k] = floatN
                if i > 0:
                    dp[i][j][k] += dp[i-1][j][k] * i
                if j > 0:
                    dp[i][j][k] += dp[i+1][j-1][k] * j
                if k > 0:
                    dp[i][j][k] += dp[i][j+1][k-1] * k
                dp[i][j][k] /= (i+j+k)

    print(dp[a][b][c])
main()
Problem p03193 (python)

Fixed submission:
N,H,W=map(int,input().split())
ans=0
for i in range(N):
  x,y=map(int,input().split())
  if x>=H and y>=W:
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
N,H,W=map(int,input().split())
ans=0
for i in range(N):
  a,b=map(int,input().split())
  if a>=H and b=W:
    ans+=1
print(ans)