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

Fixed submission:
a,b,c,d=int(input()),int(input()),int(input()),int(input())
print(min(a,b)+min(c,d))

Buggy submission (verdict: Runtime Error):
a,b,c,d=list(map(int,input().split()))
print(min(a,b)+min(c,d))
Problem p03455 (python)

Fixed submission:
i=list(map(int,input().split()))
a=i[0]*i[1]
if a%2==0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
i=list(map(int,input().split()))
a=i[0]*i[1]
if a%%2==0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
i=list(map(int,input(),split()))
a=i[0]*i[1]
if a%2==0:
  print("Evwn")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
c=a*b
if c%2==0:
  print("Even")
  else:
    print("Odd")
Problem p03636 (python)

Fixed submission:
a=input()
print(a[0]+str(len(a)-2)+a[-1])

Buggy submission (verdict: Runtime Error):
a=input()
print(a[0]+len(a)+a[-1])
Problem p03773 (python)

Fixed submission:
a,b=map(int,input().split())
if a+b<24:
  print(a+b)
else:
  print((a+b)%24)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a+b<24:
  print(a+b)
  else:
    print((a+b)%24)
Problem p02971 (python)

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
a_max = int(max(A))
count = A.count(a_max)

for i in range(N):
	if A[i] < a_max or count >= 2:
		print(a_max)
	else:
		b_max = 0
		for j in range(N):
				if A[j] == a_max:
					continue
				if A[j] > b_max:
					b_max = A[j]
		print(b_max)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
a_max = max(A)[0]
count = A.count(a_max)

for i in range(N):
	if A[i] < a_max and count >= 2:
		print(a_max)
	else:
		b_max = 0
		for j in range(N):
				if A[j] == a_max:
					continue
				if A[j] > b_max:
					b_max = A[j]
		print(b_max)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
a_max = max(A)[0]
count = A.count(a_max)

for i in range(N):
	if A[i] < a_max and count >= 2:
		print(a_max)
	else:
		b_max = 0
		for i in range(N):
				if A[i] == a_max:
					continue
				if A[i] > b_max:
					b_max = A[i]
		print(b_max)
Problem p03035 (python)

Fixed submission:
inputs = input().split()

A = int(inputs[0])
B = int(inputs[1])

if not 0 <= A <= 100:
    exit(0)

if not 2 <= B <= 1000:
    exit(0)

if not B % 2 == 0:
    exit(0)

if A <= 5:
    B = 0
elif 5 < A < 13:
    B /= 2

print(int(B))

Buggy submission (verdict: Runtime Error):
inputs = input().split()

N = int(inputs[0])
M = int(inputs[1])

passIDs = [0] * (10**5 + 10)

for i in range(M):
    inputs = input().split()

    L = int(inputs[0])
    R = int(inputs[1])

    for j in range(L, R+1):
        passIDs[j] += 1

IDs = 0

for passId in passIDs:
    if passId == M:
        IDs += 1

print(IDs)
Problem p03103 (python)

Fixed submission:
import sys

N,M = map(int,input().split())
s = {}
ans = 0

for i in range(N):
	a,b = map(int,input().split())
	if a in s.keys():
		s[a] += b
	else:
		s[a] = b

s = sorted(s.items(), key=lambda x:x[0])
for store in s:
	price = store[0]
	stock = store[1]
	if M == 0: break

	if M - stock >= 0:
		M -= stock
		ans += (stock * price)
	else:
		for i in range(stock):
			M -= 1
			ans += price
			if M == 0:
				print(ans)
				sys.exit()
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
s = {}
ans = 0

for i in range(N):
	a,b = map(int,input().split())
	if a in s.keys():
		s[a] += b
	else:
		s[a] = b

s = sorted(s.items(), key=lambda x:x[0])
for store in s:
	price = store[0]
	stock = store[1]
	if M == 0: break

	if M - stock >= 0:
		M -= stock
		ans += (stock * price)
	else:
		for i in range(stock):
			M -= 1
			ans += price
			if M == 0:
				print(ans)
				exit(1)
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
s = {}
ans = 0

for i in range(N):
	a,b = map(int,input().split())
	if a in s.keys():
		s[a] += b
	else:
		s[a] = b

s = sorted(s.items(), key=lambda x:x[0])
for store in s:
	price = store[0]
	stock = store[1]
	if M == 0: break

	if M - stock >= 0:
		M -= stock
		ans += (stock * price)
	else:
		for i in range(stock):
			M -= 1
			ans += price
			if M == 0:
				print(ans)
				exit(1)
print(ans)
Problem p03282 (python)

Fixed submission:
import sys
A = str(input())
B = int(input())
count = 0

for i in range(len(A)):
    if A[i] == "1":
        count += 1
    else:
        if B <= count:
            print(1)
            sys.exit()
        else:
            print(A[i])
            sys.exit()
print(1)

Buggy submission (verdict: Runtime Error):
A = str(input())
B = int(input())
count = 0

for i in range(len(A)):
    if A[i] == "1":
        count += 1
    else:
        if B <= count:
            print(1)
            sys.exit()
        else:
            print(A[i])
            sys.exit()
print(1)
Problem p02642 (python)

Fixed submission:
M = 10**6
N = int(input())
A = list(map(int, input().split()))


def solve():
    amax = max(A)+1
    memo = [0] * amax
    for a in A:
        i = 1
        while i*a < amax:
            memo[i*a] += 1
            i += 1

    count = 0
    for a in A:
        if memo[a] == 1:
            count += 1

    return count

if __name__ == "__main__":
    print(solve())

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


def solve():
    memo = [0] * M
    for a in A:
        i = 1
        while i*a < M:
            memo[i*a] += 1
            i += 1

    count = 0
    for a in A:
        if memo[a] == 1:
            count += 1

    return count

if __name__ == "__main__":
    print(solve())
Problem p02931 (python)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10**5)
N, H, W = map(int, input().split())
RCA = []

class UF(object):
    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, v):
        if v == self.parent[v]:
            return v
        else:
            self.parent[v] = self.root(self.parent[v])
            return self.parent[v]
    
    def unite(self, u, v):
        u, v = self.root(u), self.root(v)
        if (u == v):
            return
        self.parent[u] = v

for _ in range(N):
    r, c, a = map(int, input().split())
    r, c = r-1, c-1
    RCA.append((a, r, c))

RCA.sort(reverse=True)
RCA = deque(RCA)

uf = UF(H+W+1)  # r0, r1, ..., rH, c0, c1, ..., cW, loopflag

cnt, ans = 0, 0
while RCA and cnt < H+W:
    a, r, c = RCA.popleft()
    c += H
    if uf.root(r) == uf.root(c):
        if uf.root(r) == uf.root(H+W):  # loop?
            continue
        uf.unite(r, H+W)
    ans += a
    cnt += 1
    uf.unite(r, c)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
input = sys.stdin.readline
N, H, W = map(int, input().split())
RCA = []

class UF(object):
    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, v):
        if v == self.parent[v]:
            return v
        else:
            self.parent[v] = self.root(self.parent[v])
            return self.parent[v]
    
    def unite(self, u, v):
        u, v = self.root(u), self.root(v)
        if (u == v):
            return
        self.parent[u] = v

for _ in range(N):
    r, c, a = map(int, input().split())
    r, c = r-1, c-1
    RCA.append((a, r, c))

RCA.sort(reverse=True)
RCA = deque(RCA)

uf = UF(H+W+1)  # r0, r1, ..., rH, c0, c1, ..., cW, loopflag

cnt, ans = 0, 0
while RCA and cnt < H+W:
    a, r, c = RCA.popleft()
    c += H
    if uf.root(r) == uf.root(c):
        if uf.root(r) == uf.root(H+W):  # loop?
            continue
        uf.unite(r, H+W)
    ans += a
    cnt += 1
    uf.unite(r, c)

print(ans)
Problem p02936 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, Q = map(int, input().split())
V = {i: [] for i in range(1,N+1)}
for _ in range(N-1):
    a, b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)

C = {i: 0 for i in range(1,N+1)}

for _ in range(Q):
    p, x = map(int, input().split())
    C[p] += x


def propagate(u, p):
    for v in V[u]:
        if v == p:
            continue
        C[v] += C[u]
        propagate(v, u)

propagate(1, 0)

print(' '.join(str(C[i]) for i in range(1,N+1)))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5 * 2)

N, Q = map(int, input().split())
V = {i: [] for i in range(1,N+1)}
for _ in range(N-1):
    a, b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)

C = {i: 0 for i in range(1,N+1)}

for _ in range(Q):
    p, x = map(int, input().split())
    C[p] += x


def propagate(u, p):
    for v in V[u]:
        if v == p:
            continue
        C[v] += C[u]
        propagate(v, u)

propagate(1, 0)

print(' '.join(str(C[i]) for i in range(1,N+1)))

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
V = {i: [] for i in range(1,N+1)}
for _ in range(N-1):
    a, b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)

C = {i: 0 for i in range(1,N+1)}

for _ in range(Q):
    p, x = map(int, input().split())
    C[p] += x


def propagate(u, p):
    for v in V[u]:
        if v == p:
            continue
        C[v] += C[u]
        propagate(v, u)

propagate(1, 0)

print(' '.join(str(C[i]) for i in range(1,N+1)))
Problem p02960 (python)

Fixed submission:
S = input()
N = len(S)
MOD = 10 ** 9 + 7

dp = [0 for _ in range(13)]
pp = [0 for _ in range(13)]

dp[0] = 1
for i in range(N):
    pp, dp = dp, pp
    for d in range(13):
        dp[d] = 0
    s = S[N-i-1]
    b = pow(10, i, 13)
    if s == '?':
        for d in range(13):
            for e in range(10):
                dp[(d+b*e)%13] += pp[d]
                dp[(d+b*e)%13] %= MOD
    else:
        s = int(s)
        for d in range(13):
            dp[(d+b*s)%13] += pp[d]
            dp[(d+b*s)%13] %= MOD

print(dp[5])

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)
MOD = 10 ** 9 + 7

dp = [0 for _ in range(13)]
dp[0] = 1
for i in range(N):
    pp = dp.copy()
    dp = [0 for _ in range(13)]
    s = S[N-i-1]
    b = pow(10, i, 13)
    if s == '?':
        for d in range(13):
            for e in range(10):
                dp[(d+b*e)%13] += pp[d]
                dp[(d+b*e)%13] %= MOD
    else:
        s = int(s)
        for d in range(13):
            dp[(d+b*s)%13] += pp[d]
            dp[(d+b*s)%13] %= MOD

print(dp[5])
Problem p02992 (python)

Fixed submission:
from collections import deque
N, K = map(int, input().split())
MOD = 10 ** 9 + 7

# guchoku case

# dp = [[0 for _ in range(N+1)] for _ in range(K+1)]

# for i in range(N+1):
#     dp[1][i] = 1
# for i in range(K):
#     for j in range(1,N+1):
#         for k in range(1, N // j + 1):
#             dp[i+1][j] += dp[i][k]
#             dp[i+1][j] %= MOD

JN = deque()  # N//j table
SQN = int(N**0.5)
JN.append(SQN)

if SQN**2 != N:
    JN.append(N//SQN)
for j in range(SQN-1, 0, -1):
    JN.appendleft(j)
    JN.append(N//j)
JN.appendleft(0)

# JN.sort()
# PJN = {JN[i]: JN[i-1] for i in range(1, len(JN))}  # prev jn
LJN = len(JN)

dp = [[0 for _ in range(LJN)] for _ in range(K)]
cdp = [[0 for _ in range(LJN)] for _ in range(K)]
w = [0 for _ in range(LJN)]

# init dp
prv = 0
for i in range(1,LJN):
    jn = JN[i]
    dp[0][i] = 1
    w[i] = jn - prv
    cdp[0][i] = jn
    prv = JN[i]

for i in range(K-1):
    for j in range(1,LJN):
        dp[i+1][j] = cdp[i][LJN-j]
        dp[i+1][j] %= MOD
        cdp[i+1][j] = cdp[i+1][j-1] + dp[i+1][j] * w[j]
        cdp[i+1][j] %= MOD

print(cdp[-1][-1])

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
MOD = 10 ** 9 + 7

# guchoku case

# dp = [[0 for _ in range(N+1)] for _ in range(K+1)]

# for i in range(N+1):
#     dp[1][i] = 1
# for i in range(K):
#     for j in range(1,N+1):
#         for k in range(1, N // j + 1):
#             dp[i+1][j] += dp[i][k]
#             dp[i+1][j] %= MOD

JN = [0]  # N//j table
j = 1
while j*j<N:
    if j not in JN:
        JN.append(j)
    if N//j not in JN:
        JN.append(N//j)
    j += 1

JN.sort()
PJN = {JN[i]: JN[i-1] for i in range(1, len(JN))}  # prev jn

dp = [{0: 0} for _ in range(K)]
cdp = [{0: 0} for _ in range(K)]
w = dict()

# init dp
prv = 0
for i, jn in enumerate(JN):
    dp[0][jn] = 1
    w[jn] = jn - prv
    cdp[0][jn] = jn
    prv = JN[i]

for i in range(K-1):
    for jn in JN[1:]:
        dp[i+1][jn] = cdp[i][N//jn]
        dp[i+1][jn] %= MOD
        cdp[i+1][jn] = cdp[i+1][PJN[jn]] + dp[i+1][jn] * w[jn]
        cdp[i+1][jn] %= MOD

print(cdp[-1][N])
Problem p03006 (python)

Fixed submission:
from itertools import combinations

N = int(input())
P = []
for _ in range(N):
    x, y = map(int, input().split())
    P.append((x, y))

memo = dict()
for (a, b) in combinations(P, 2):
    p, q = a[0] - b[0], a[1] - b[1]
    if p < 0:
        p, q = -p, -q
    elif p == 0 and q < 0:
        q = -q
    if (p, q) in memo:
        memo[(p, q)] += 1
    else:
        memo[(p, q)] = 1

print(N - max(memo.values()) if N > 1 else 1)

Buggy submission (verdict: Runtime Error):
from itertools import combinations

N = int(input())
P = []
for _ in range(N):
    x, y = map(int, input().split())
    P.append((x, y))

memo = dict()
for (a, b) in combinations(P, 2):
    p, q = a[0] - b[0], a[1] - b[1]
    if p < 0:
        p, q = -p, -q
    elif p == 0 and q < 0:
        q = -q
    if (p, q) in memo:
        memo[(p, q)] += 1
    else:
        memo[(p, q)] = 1

print(N - max(memo.values()))
Problem p03061 (python)

Fixed submission:
import fractions
import itertools

n = int(input())
as_ = [int(i) for i in input().split()]


def gcds(list_):
    return list(itertools.accumulate(list_, fractions.gcd))


def reversed_gcds(list_):
    return list(itertools.accumulate(reversed(list_), fractions.gcd))


as_accum_gcd, as_rev_accum_gcd = gcds(as_), reversed_gcds(as_)

dropped_gcds = []
for i in range(len(as_)):
    if i == 0:
        dropped_gcd = as_rev_accum_gcd[-2]
    elif i == len(as_) - 1:
        dropped_gcd = as_accum_gcd[-2]
    else:
        dropped_gcd = fractions.gcd(as_accum_gcd[i - 1], as_rev_accum_gcd[-2 - i])
    dropped_gcds.append(dropped_gcd)

print(max(dropped_gcds))

Buggy submission (verdict: Runtime Error):
import math
import functools

n = int(input())
as_ = [int(i) for i in input().split()]


def gcds(list_):
    return functools.reduce(math.gcd, list_)


def drop(list_, i):
    list_copy = list_.copy()
    del list_copy[i]
    return list_copy


print(max(gcds(drop(as_, i)) for i, _ in enumerate(as_)))
Problem p03078 (python)

Fixed submission:
# input
x, y, z, k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ab = []
ab.extend([i+j for j in b for i in a])
ab.sort(reverse=True)

abc = []
abc.extend([i+j for j in ab[:k] for i in c])
abc.sort(reverse=True)

print('\n'.join(str(i) for i in abc[:k]))

Buggy submission (verdict: Runtime Error):
# input
x, y, z, k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

import heapq


a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

index_hstr = []
deliciouses = []
# priority queue
pq = []
heapq.heappush(pq, (-a[0] - b[0] - c[0], 0, 0, 0))
index_hstr.append((0, 0, 0))

for t in range(k):
    deli, i, j, k = heapq.heappop(pq)
    if (i+1, j, k) not in index_hstr:
        heapq.heappush(pq, (-a[i+1] - b[j] - c[k], i+1, j, k))
        index_hstr.append((i+1, j, k))
    if (i, j+1, k) not in index_hstr:
        heapq.heappush(pq, (-a[i] - b[j+1] - c[k], i, j+1, k))
        index_hstr.append((i, j+1, k))
    if (i, j, k+1) not in index_hstr:
        heapq.heappush(pq, (-a[i] - b[j] - c[k+1], i, j, k+1))
        index_hstr.append((i, j, k+1))
    deliciouses.append(-deli)


pass
Problem p03148 (python)

Fixed submission:
from heapq import heappop, heappush
N, K = map(int, input().split())
KMAX = 10 ** 5 + 1
TD = []
for _ in range(N):
    t, d = map(int, input().split())
    TD.append((d, t))

TD.sort(reverse=True)

pioneer = []
successor = []
appear = [False] * KMAX
cnt = 0
nsp = 0  # num of species
base = 0
best = []

for td in TD:
    d, t = td
    if cnt < K:
        heappush(successor if appear[t] else pioneer, (d, t))
        nsp += 0 if appear[t] else 1
        appear[t] = True
        base += d
        cnt += 1
        if cnt == K:
            heappush(best, -(base + nsp ** 2))
        continue
    if not successor:
        break
    if appear[t]:
        continue
    cd, ct = heappop(successor)
    appear[t] = True
    heappush(pioneer, (d, t))
    base += (d-cd)
    nsp += 1
    heappush(best, -(base + nsp ** 2))

print(-heappop(best))

Buggy submission (verdict: Runtime Error):
from heapq import heappop, heappush
N, K = map(int, input().split())
KMAX = 10 ** 5 + 1
TD = []
for _ in range(N):
    t, d = map(int, input().split())
    TD.append((d, t))

TD.sort(reverse=True)

pioneer = []
successor = []
appear = [False] * KMAX
cnt = 0
nsp = 0  # num of species
base = 0
best = []

for td in TD:
    d, t = td
    if cnt < K:
        heappush(successor if appear[t] else pioneer, (d, t))
        nsp += 0 if appear[t] else 1
        appear[t] = True
        base += d
        cnt += 1
        if cnt == K-1:
            heappush(best, -(base + nsp ** 2))
        continue
    if not successor:
        break
    if appear[t]:
        continue
    cd, ct = heappop(successor)
    appear[t] = True
    heappush(pioneer, (d, t))
    base += (d-cd)
    nsp += 1
    heappush(best, -(base + nsp ** 2))

print(-heappop(best))

Buggy submission (verdict: Runtime Error):
from heapq import heappop, heappush
N, K = map(int, input().split())
KMAX = 10 ** 5 + 1
TD = []
for _ in range(N):
    t, d = map(int, input().split())
    TD.append((d, t))

TD.sort(reverse=True)

pioneer = []
successor = []
appear = [False] * KMAX
cnt = 0
nsp = 0  # num of species
base = 0
best = []

for td in TD:
    d, t = td
    if cnt < K:
        heappush(successor if appear[t] else pioneer, (d, t))
        nsp += 0 if appear[t] else 1
        appear[t] = True
        base += d
        cnt += 1
        continue
    elif cnt == K:
        heappush(best, -(base + nsp ** 2))
    if not successor:
        break
    if appear[t]:
        continue
    cd, ct = heappop(successor)
    appear[t] = True
    heappush(pioneer, (d, t))
    base += (d-cd)
    nsp += 1
    heappush(best, -(base + nsp ** 2))

print(-heappop(best))
Problem p03165 (python)

Fixed submission:
S = input()
T = input()

# dp = [[[] for _ in range(len(S)+1)] for _ in range(len(T)+1)]
cdp = [[None for _ in range(len(S)+1)] for _ in range(len(T)+1)]
ddp = [[None for _ in range(len(S)+1)] for _ in range(len(T)+1)]
# dp[0] = [[''] for _ in range(len(S)+1)]
cdp[0] = [0 for _ in range(len(S)+1)]
ddp[0] = [0 for _ in range(len(S)+1)]

for i in range(1,len(T)+1):
    for j in range(len(S)+1):
        if j == 0:
            # dp[i][j] = ['']
            cdp[i][j] = 0
            ddp[i][j] = 0
            continue
        if S[j-1] == T[i-1]:
            # dp[i][j] = [p + S[j-1] for p in dp[i-1][j-1]]
            cdp[i][j] = cdp[i-1][j-1] + 1
            ddp[i][j] = 2
        else:
            if cdp[i][j-1] > cdp[i-1][j]:
                # dp[i][j] = dp[i][j-1]
                cdp[i][j] = cdp[i][j-1]
                ddp[i][j] = 1
            else:
                # dp[i][j] = dp[i-1][j]
                cdp[i][j] = cdp[i-1][j]
                ddp[i][j] = 0

# print(dp[-1][-1][0])

i, j = len(T), len(S)
L = ''
while i > 0 and j > 0:
    if ddp[i][j] == 2:
        i -= 1
        j -= 1
        L += T[i]
    elif ddp[i][j] == 1:
        j -= 1
    elif ddp[i][j] == 0:
        i -= 1

print(L[::-1])

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

dp = [[[] for _ in range(len(S)+1)] for _ in range(len(T)+1)]
cdp = [[None for _ in range(len(S)+1)] for _ in range(len(T)+1)]
dp[0] = [[''] for _ in range(len(T)+1)]
cdp[0] = [0 for _ in range(len(T)+1)]

for i in range(1,len(T)+1):
    for j in range(len(S)+1):
        if j == 0:
            dp[i][j] = ['']
            cdp[i][j] = 0
            continue
        if S[j-1] == T[i-1]:
            dp[i][j] = [p + S[j-1] for p in dp[i-1][j-1]]
            cdp[i][j] = cdp[i-1][j-1] + 1
        else:
            if cdp[i][j-1] > cdp[i-1][j]:
                dp[i][j] = dp[i][j-1]
                cdp[i][j] = cdp[i][j-1]
            else:
                dp[i][j] = dp[i-1][j]
                cdp[i][j] = cdp[i-1][j]

print(dp[-1][-1][0])
Problem p03166 (python)

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

N, M = map(int, input().split())
V = [[] for _ in range(N)]
for _ in range(M):
    x, y = map(lambda x: int(x) - 1, input().split())
    V[x].append(y)

dp = [None for _ in range(N)]

def dfs(x):
    if dp[x] is not None:
        return dp[x]
    if not V[x]:
        dp[x] = 0
        return 0
    l = max(dfs(v) for v in V[x]) + 1
    dp[x] = l
    return l

print(max(dfs(v) for v in range(N)))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
V = [[] for _ in range(N)]
for _ in range(M):
    x, y = map(lambda x: int(x) - 1, input().split())
    V[x].append(y)

dp = [None for _ in range(N)]

def dfs(x):
    if dp[x] is not None:
        return dp[x]
    if not V[x]:
        dp[x] = 0
        return 0
    l = max(dfs(v) for v in V[x]) + 1
    dp[x] = l
    return l

print(max(dfs(v) for v in range(N)))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
V = [[] for _ in range(N)]
for _ in range(M):
    x, y = map(lambda x: int(x) - 1, input().split())
    V[x].append(y)

dp = [None for _ in range(N)]

def dfs(x):
    if dp[x] is not None:
        return dp[x]
    if not V[x]:
        dp[x] = 0
        return 0
    l = max(dfs(v) for v in V[x]) + 1
    dp[x] = l
    return l

print(max(dfs(v) for v in range(N)))
Problem p03245 (python)

Fixed submission:
N = int(input())
P = [tuple(map(int, input().split())) for _ in range(N)]

odd = []
for (x, y) in P:
    dist = abs(x) + abs(y)
    odd.append(dist % 2 != 0)

valid = True
even = False
if all(odd):
    pass
elif not any(odd):
    even = True
else:
    valid =False

if valid:

    M = 31
    if even:
        print(M+1)
        print(*([1 << m for m in range(M)] + [1]))
    else:
        print(M)
        print(*[1 << m for m in range(M)])

    for (x, y) in P:
        u = x + y
        v = x - y
        if even:
            u += 1
            v += 1
        if u >= 0 and v >= 0:
            A = 'R'
            B = 'U'
            C = 'D'
            D = 'L'
        elif u >= 0 and v < 0:
            v *= -1
            A = 'U'
            B = 'R'
            C = 'L'
            D = 'D'
        elif u < 0 and v >= 0:
            u *= -1
            A = 'D'
            B = 'L'
            C = 'R'
            D = 'U'
        elif u < 0 and v < 0:
            u *= -1
            v *= -1
            A = 'L'
            B = 'D'
            C = 'U'
            D = 'R'

        ans = ''
        wa = ((1 << M) - 1 - u) // 2
        sa = ((1 << M) - 1 - v) // 2
        for i in range(M):
            check = str(wa >> i & 1) + str(sa >> i & 1)
            if check == '00':
                ans += A
            elif check == '01':
                ans += B
            elif check == '10':
                ans += C
            elif check == '11':
                ans += D
        if even:
            ans += 'L'
        print(ans)
else:
    print(-1)

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

max_dist = 0
judge = []
for (x, y) in P:
    dist = abs(x) + abs(y)
    max_dist = max(max_dist, dist)
    judge.append(dist % 2 == 0)

if all(judge) or not any(judge):
    print(max_dist)
    print(*([1] * max_dist))
    for (x, y) in P:
        com = ''
        com += abs(x) * ('R' if x > 0 else 'L')
        com += abs(y) * ('U' if y > 0 else 'D')
        com += 'LR' * ((max_dist - abs(x) - abs(y)) // 2)
        print(com)
else:
    print(-1)