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

Fixed submission:
N = int(input())
A_list = []

hoge = input().split()

for i in range(N):
  A_list.append(int(hoge[i]))
  
len_org = len(A_list)
len_uniq = len(list(set(A_list)))

if len_org == len_uniq:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
N = int(input())
A_list = []

for i in range(N):
  A_list.append(int(input()))
  
len_org = len(A_list)
len_uniq = len(list(set(A_list)))

if len_org == len_uniq:
  print("YES")
else:
  print("NO")
Problem p02935 (python)

Fixed submission:
N = int(input())
hoge = input().split()
v = []
for i in range(N):
  v.append(int(hoge[i]))

_v = sorted(v, reverse=True)

gu = _v.pop(N-1)
if N == 2:
  print((_v[0]+gu)/2)
else:
  for i in range(N-2,-1,-1):
    gu = (gu + _v.pop(i))/2
  print(gu)

Buggy submission (verdict: Runtime Error):
N = int(input())
hoge = input().split()
v = []
for i in range(N):
  v.append(int(hoge[i]))

_v = sorted(v, reverse=True)

gu = _v.pop(N-1)
if N == 2:
  print((_v[0]+_v[1])/2)
else:
  for i in range(N-2,-1,-1):
    gu = (gu + _v.pop(i))/2
  print(gu)
Problem p03013 (python)

Fixed submission:
N, M = list(map(int,input().split()))
     
b = [0]*(N+2)
b[0] = 1
     
for i in range(M):
  b[int(input())] = -1
     
for i in range(N):
  if b[i] != -1:
    if b[i+1] != -1:
      b[i+1] += b[i]
    if b[i+2] != -1:
      b[i+2] += b[i]

print(b[N]%1000000007)

Buggy submission (verdict: Runtime Error):
hoge = input().split()
N = int(hoge[0])
M = int(hoge[1])
broken = []
for i in range(M):
  broken.append(int(input()))

anss = []
safes = []
fibo = [1,2]
safes.append(broken[0]-1)
for i in range(M-1):
  safes.append(broken[i+1] - broken[i] - 1)

safes.append(N-broken[M-1] - 1)

for i in range(len(safes)):
  if safes[i] == 0:
    anss.append(1) # 間が0
  elif safes[i] == 1:
    anss.append(1) # 間が1つ
  elif safes[i] == 2:
    anss.append(2) # 間が2つ
  else:
    for i in range(safes[i] - 2): # 間が3つ以上
      fibo.append(fibo[i] + fibo[i+1])
    anss.append(fibo.pop())
    fibo = [1, 2]

answer = 1
#print(safes)
#print(anss)
for i in range(len(anss)):
  answer = answer * anss[i]
# print(safes)
  
flag = 0
for i in range(M-1):
  if broken[i+1] - broken[i] == 1:
    flag = 1

if flag == 0:
  print(answer%1000000007)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
hoge = input().split()
N = int(hoge[0])
M = int(hoge[1])
broken = []
for i in range(M):
  broken.append(int(input()))

anss = []
safes = []
fibo = [1,2]
safes.append(broken[0]-1)
for i in range(M-1):
  safes.append(broken[i+1] - broken[i] - 1)

safes.append(N-broken[M-1] - 1)

for i in range(len(safes)):
  if safes[i] == 0:
    anss.append(1) # 間が0
  elif safes[i] == 1:
    anss.append(1) # 間が1つ
  elif safes[i] == 2:
    anss.append(2) # 間が2つ
  else:
    for i in range(safes[i] - 2): # 間が3つ以上
      fibo.append(fibo[i] + fibo[i+1])
    anss.append(fibo.pop())
    fibo = [1, 2]

answer = 1
print(safes)
print(anss)
for i in range(len(anss)):
  answer = answer * anss[i]
# print(safes)
  
flag = 0
for i in range(M-1):
  if broken[i+1] - broken[i] == 1:
    flag = 1

if flag == 0:
  print(answer%1000000007)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
import sys
hoge = input().split()
N = int(hoge[0])
M = int(hoge[1])
broken = []
for i in range(M):
  broken.append(int(input()))

anss = []
safes = []
fibo = [1,2]
safes.append(broken[0]-1)
for i in range(M-1):
  safes.append(broken[i+1] - broken[i] - 1)

safes.append(N-broken[M-1] - 1)

for i in range(len(safes)):
  if safes[i] == 0:
    anss.append(1) # 間が0
  elif safes[i] == 1:
    anss.append(1) # 間が1つ
  elif safes[i] == 2:
    anss.append(2) # 間が2つ
  else:
    for i in range(safes[i] - 2): # 間が3つ以上
      fibo.append(fibo[i] + fibo[i+1])
    anss.append(fibo.pop())
    fibo = [1, 2]

answer = 1
print(safes)
print(anss)
for i in range(len(anss)):
  answer = answer * anss[i]
# print(safes)
  
flag = 0
for i in range(M-1):
  if broken[i+1] - broken[i] == 1:
    flag = 1

if flag == 0:
  print(answer%1000000007)
else:
  print(0)
Problem p03041 (python)

Fixed submission:
hoge = input().split()
s = input()
n = int(hoge[0])
k = int(hoge[1])
new_s = s[:k-1] + s[k-1].lower() + s[k:]
print(new_s)

Buggy submission (verdict: Runtime Error):
hoge = input().split()
n = int(hoge[0])
k = int(hoge[1])
s = hoge[2]
new_s = s[:k-1] + s[k-1].lower() + s[k:]
print(new_s)
Problem p03042 (python)

Fixed submission:
hoge = str(input())
a = int(hoge[:2])
b = int(hoge[2:4])
result = None

if 0 < a and a <= 12:
  result = "MMYY"
  if 0 < b and b <= 12:
    result = "AMBIGUOUS"
if 0 < b and b <= 12:
  result = "YYMM"
  if 0 < a and a <= 12:
    result = "AMBIGUOUS"
if result == None:
  result = "NA"

print(result)

Buggy submission (verdict: Runtime Error):
hoge = str(input())
a = int(hoge[:2])
b = int(hoge[2:4])

if 0 < a and a <= 12:
  result = "MMYY"
  if 0 < b and b <= 12:
    result = "AMBIGUOUS"
if 0 < b and b <= 12:
  result = "YYMM"
  if 0 < a and a <= 12:
    result = "AMBIGUOUS"
if result == None:
  result = "NA"

print(result)

Buggy submission (verdict: Runtime Error):
hoge = str(input())
a = int(hoge[:2])
b = int(hoge[2:4])

if 0 < a and a < 12:
  result = "YYMM"
  if 0 < b and b < 12:
    result = "AMBIGUOUS"
if 0 < b and b < 12:
  result = "MMYY"
  if 0 < a and a < 12:
    result = "AMBIGUOUS"
if result == None:
  result = "NA"

print(result)

Buggy submission (verdict: Runtime Error):
hoge = str(input())
a = int(hoge[:2])
b = int(hoge[2:4])

if 0 < a and a < 12:
  result = "YYMM"
  if 0 < a and a < 12:
    result = "AMBIGUOUS"
if 0 < b and b < 12:
  result = "MMYY"
  if 0 < a and a < 12:
    result = "AMBIGUOUS"
if result == None:
  result = "NA"

print(result)

Buggy submission (verdict: Runtime Error):
hoge = str(input())
a = int(hoge[:2])
b = int(hoge[2:4])

if a == 0 or b == 0:
  result = "NA"

if 0 < a and a < 12:
  result = "YYMM"
  if 0 < a and a < 12:
    result = "AMBIGUOUS"
if 0 < b and b < 12:
  result = "MMYY"
  if 0 < a and a < 12:
    result = "AMBIGUOUS"

print(result)
Problem p02623 (python)

Fixed submission:
n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
from itertools import accumulate
AS = [0] + list(accumulate(A))
BS = [0] + list(accumulate(B))

ans = 0
j = m
for i in range(n+1):
    if AS[i] > k:
        break

    while AS[i] + BS[j] > k:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)

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

from collections import deque
q = deque([[0, 0, 0]])
ans = 0
while q:
    t, ai, bi = q.pop()
    if t > k:
        continue
    ans = max(ans, ai+bi)

    if ai < n:
        q.append([t + A[ai], ai+1, bi])
    if bi < m:
        q.append([t + B[ai], ai, bi+1])

print(ans)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
SA = sum(A)
SB = sum(B)

if SA+SB <= k:
    print(len(A) + len(B))
else:
    t = 0
    ai = 0; bi = 0
    while True:
        if bi == m or A[ai] < B[bi]:
            t += A[ai]
            ai += 1
        else:
            t += B[bi]
            bi += 1

        if t >= k:
            break
    print(ai + bi - 1)
Problem p02661 (python)

Fixed submission:
n = int(input())

AB = []
for _ in range(n):
    ab = tuple(map(int, input().split()))
    AB.append(ab)

AB_A = sorted(AB, key=lambda x: x[0])
AB_B = sorted(AB, key=lambda x: x[1])

if n%2==1:
    sa, sb = AB_A[n//2]
    la, lb = AB_B[n//2]
    print(lb - sa + 1)
else:
    sal, sbl = AB_A[n//2-1]
    sar, sbr = AB_A[n//2]

    lal, lbl = AB_B[n//2-1]
    lar, lbr = AB_B[n//2]
    print((lbl + lbr) - (sal + sar) +1)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = []
B = []
for _ in range(n):
    a, b = tuple(map(int, input().split()))
    A.append(a)
    B.append(b)

A = sorted(A)
B = sorted(B)

if n%2==1:
    sa = AB_A[n//2]
    lb = AB_B[n//2]
    print(lb - sa + 1)
else:
    sal = AB_A[n//2-1]
    sar = AB_A[n//2]

    lbl = AB_B[n//2-1]
    lbr = AB_B[n//2]
    print((lbl + lbr) - (sal + sar) +1)
Problem p02699 (python)

Fixed submission:
S, W = map(int, input().split())
if W >= S:
    print('unsafe')
else:
    print('safe')

Buggy submission (verdict: Runtime Error):
S, W = map(int, input().split())
if W >= S:
    print('unsafe')
else:
    print('safe'
Problem p02831 (python)

Fixed submission:
A, B = map(int, input().split())
 
import fractions
l = A * B / fractions.gcd(A, B)
print(int(l))

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

import math
l = A * B / math.gcd(A, B)
print(int(l))
Problem p02862 (python)

Fixed submission:
X, Y = map(int, input().split())
mod = 10**9 + 7

if (X + Y) % 3 != 0 or X > 2*Y or Y > 2*X:
    print(0)
else:
    n2x = (2*X - Y) // 3
    n1x = (2*Y - X) // 3
    n = n2x + n1x

    # nCn2xを求める
    def combs(n,n2x):
        invs = [1] * (n+1)
        nfac = 1
        for i in range(1, n+1):
            nfac = nfac * i % mod
            invs[i] = pow(nfac, mod-2, mod)
        return nfac * invs[n2x] * invs[n-n2x] % mod

    print(combs(n, n2x))

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())
mod = 10**9 + 7

if (X + Y) % 3 != 0:
    print(0)
else:
    n2x = (2*X - Y) // 3
    n1x = (2*Y - X) // 3
    n = n2x + n1x

    # nCn2xを求める
    def combs(n,n2x):
        facs = [1] * (n+1)
        invs = [1] * (n+1)
        nfac = 1
        for i in range(1, n+1):
            nfac = nfac * i % mod
            facs[i] = nfac
            invs[i] = pow(facs[i], mod-2, mod)
        return facs[n] * invs[n2x] * invs[n-n2x] % mod

    print(combs(n, n2x))

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())
mod = 10**9 + 7

if (X + Y) % 3 != 0:
    print(0)
else:
    n2x = (2*X - Y) // 3
    n1x = (2*Y - X) // 3
    n = n2x + n1x

    # nCn2xを求める
    facs = [1] * (n+1)
    invs = [1] * (n+1)
    nfac = 1
    for i in range(1, n+1):
        nfac = nfac * i % mod
        facs[i] = nfac
        invs[i] = pow(facs[i], mod-2, mod)
    
    combs = facs[n] * invs[n2x] * invs[n-n2x] % mod
    print(combs)
Problem p02881 (python)

Fixed submission:
import math
N = int(input())

minlen = 10**12
for i in range(1, int(math.sqrt(N))+1):
    if N%i == 0:
        minlen = min(minlen, i + N//i - 2)

if minlen == 10**9:
    print(N-1)
else:
    print(minlen)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
factors = []

while N % 2 == 0:
    factors.append(2)
    N //= 2
f = 3
while f*f <= N:
    if N % f == 0:
        factors.append(f)
        N //= f
    else:
        f += 2

if not factors:
    print(N-1)
else:
    if N > 1:
        factors.append(N)

    n = len(factors)
    sums = []
    for i in range(1, n**2-1):
        l = 1
        r = 1
        for j in range(n):
            if (i >> j) & 1:
                l *= factors[j]
            else:
                r *= factors[j]
        sums.append(l-1 + r-1)
    print(min(sums))
Problem p03013 (python)

Fixed submission:
n, m = map(int, input().split())
mod = 10**9+7
facs = [1] * (n-m+1)
invs = [1] * (n-m+1)
nfac = 1
for i in range(1, n-m+1):
    nfac = nfac * i % mod
    facs[i] = nfac
    invs[i] = pow(facs[i], mod-2, mod)

ans = 1
start = 0
def steps(start, end):
    t = end - start
    pat = 0
    for j in range(t//2+1):
        pat += (facs[t-j] * invs[j] * invs[t-j-j]) % mod
    return pat%mod

for i in range(m):
    a = int(input())
    end = a-1
    if start == end+1:
        print(0)
        break
    # startからendまで行く方法
    ans *= steps(start, end)
    ans %= mod
    start = a+1
else:
    ans *= steps(start, n)
    ans %= mod
    print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
mod = 10**9+7
facs = [1] * n
invs = [1] * n
nfac = 1
for i in range(1, n-m+1):
    nfac = nfac * i % mod
    facs[i] = nfac
    invs[i] = pow(facs[i], mod-2, mod)

ans = 1
start = 0
def steps(start, end):
    t = end - start
    pat = 0
    for j in range(t//2+1):
        pat += (facs[t-j] * invs[j] * invs[t-j-j]) % mod
    return pat%mod

for i in range(m):
    a = int(input())
    end = a-1
    if start == end+1:
        print(0)
        break
    # startからendまで行く方法
    ans *= steps(start, end)
    ans %= mod
    start = a+1
else:
    ans *= steps(start, n)
    ans %= mod
    print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
mod = 10**9+7
facs = [1] * n
invs = [1] * n
nfac = 1
for i in range(1, n-m+1):
    nfac = nfac * i % mod
    facs[i] = nfac
    invs[i] = pow(facs[i], mod-2, mod)

ans = 1
start = 0
def steps(start, end):
    t = end - start
    pat = 0
    for j in range(-(-t//2)+1):
        pat += (facs[t-j] * invs[j] * invs[t-j-j]) % mod
    return pat

for i in range(m):
    a = int(input())
    end = a-1
    if start == end+1:
        print(0)
        break
    # startからendまで行く方法
    ans *= steps(start, end)
    ans %= mod
    start = a+1
else:
    ans *= steps(start, n)
    ans %= mod
    print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
mod = 10**9+7
facs = [1] * (n-m)
invs = [1] * (n-m)
nfac = 1
for i in range(1, n-m):
    nfac = nfac * i % mod
    facs[i] = nfac
    invs[i] = pow(facs[i], mod-2, mod)

ans = 1
start = 0
for i in range(m+1):
    try:
        a = int(input())
        end = a-1
    except:
        end = n
    if start-1 == end:
        print(0)
        break
    # startからendまで行く方法
    t = end-start
    pat = 0
    for j in range(-(-t//2)+1):
        pat += (facs[t-j] * invs[j] * invs[t-j-j]) % mod
    ans *= pat
    ans %= mod
    start = a+1
else:
    print(ans)
Problem p03104 (python)

Fixed submission:
a, b = map(int, input().split())
if a == b:
    print(a)
else:
    bits = []
    for i in range(b.bit_length()):
        k = pow(2, i+1)
        nb, rb = divmod(b, k)
        na, ra = divmod(max(0,a-1), k)

        bb = nb*(k//2) + max(0, rb - k//2 + 1)
        aa = na*(k//2) + max(0, ra - k//2 + 1)
        bits.append((bb-aa)%2)
    # print(bits)
    print(int(''.join(map(str, bits[::-1])), 2))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
bits = []
for i in range(b.bit_length()):
    k = pow(2, i+1)
    nb, rb = divmod(b, k)
    na, ra = divmod(max(0,a-1), k)

    bb = nb*(k//2) + max(0, rb - k//2 + 1)
    aa = na*(k//2) + max(0, ra - k//2 + 1)
    bits.append((bb-aa)%2)
print(int(''.join(map(str, bits[::-1])), 2))
Problem p03326 (python)

Fixed submission:
n, m = map(int, input().split())
xyz = [tuple(map(int, input().split())) for _ in range(n)]
ans = 0
from itertools import product
for p in product([-1, 1], repeat=3):
    xyz_ = map(lambda l: l[0]*p[0] + l[1]*p[1] + l[2]*p[2], xyz)
    xyz_ = sorted(xyz_, reverse=True)
    ans = max(ans, sum(xyz_[:m]))
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
xyz = [tuple(map(int, input().split())) for _ in range(n)]
def isum(i, x, y, z):
    s = 0
    s += x if (i>>0)&1 else -x
    s += y if (i>>1)&1 else -y
    s += z if (i>>2)&1 else -z
    return s
ans = 0
for i in range(2**3):
    dp = [0 for _ in range(m+1)]
    for k in range(n):
        x, y, z = xyz[k]
        ndp = [0 for _ in range(m+1)]
        for j in range(1, k+1):
            # iを含める場合は、一つ前のj-1から
            # iを含めない場合は、一つ前のjから
            sumj_1 = dp[j-1]
            sj_1 = sumj_1 + isum(i, x, y, z)
            noinc_sum = dp[j]
            ndp[j] = max(sj_1, noinc_sum)

        dp = ndp
    ans = max(ans, dp[-1])
print(ans)
Problem p02793 (python)

Fixed submission:
def pow_r(x, n, P):
  if n == 0:
    return 1
  if n % 2 == 0:
    return pow_r(x ** 2 % P, n // 2, P)
  else:
    return x * pow_r(x ** 2 % P, n // 2, P) 

from fractions import gcd

N = int(input())
As = list(map(int, input().split()))
P = 10**9+7

if N == 1:
  print(1)
  exit()

lcm = As[0]*As[1]//gcd(As[0],As[1])
 
for i in range(2,N):
  c = gcd(lcm, As[i])
  lcm *= As[i]//c

rlt = 0
for a in As:
  rlt += lcm*pow_r(a, P-2, P) % P
  rlt %= P
print(rlt)

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

N = int(input())
As = list(map(int, input().split()))
P = 10**9+7

if N == 1:
  print(1)
  exit()

lcm = As[0]*As[1]//gcd(As[0],As[1])
 
for i in range(2,N):
  c = gcd(lcm, As[i])
  lcm *= As[i]//c

Buggy submission (verdict: Runtime Error):
from fractions import gcd 

N = int(input())
As = list(map(int, input().split()))
P = 10**9+7

lcm = As[0]*As[1]//gcd(As[0],As[1])

for i in range(2,N):
  c = gcd(lcm, As[i])
  lcm *= As[i]//c
  
rlt = 0
for a in As:
  rlt += lcm//a
  rlt %= P

print(rlt)
Problem p02912 (python)

Fixed submission:
import heapq
 
N, M = map(int, input().split(" "))
As = [-i for i in map(int, input().split(" "))]
As.sort()
heapq.heapify(As)

for _ in range(M):
  i = - heapq.heappop(As)
  i = i >> 1
  heapq.heappush(As,-i)

print(-sum(As))

Buggy submission (verdict: Runtime Error):
import bisect

N, M = map(int, input().split(" "))
As = [0]+list(map(int, input().split(" ")))
As = sorted(As)
cnt = 0
cnt2 = 1
for _ in range(M):
  i = As[-1-cnt]  
  i = i//(2>>cnt2)
  if i < As[-1-cnt-1]:
    cnt += 1
    cnt2 = 1
    bisect.insort_left(As,i)
  else:
    cnt2 += 1

print(sum(As[:-cnt]))

Buggy submission (verdict: Runtime Error):
import bisect

N, M = map(int, input().split(" "))
As = list(map(int, input().split(" ")))
As = sorted(As)
cnt = 0
j = 0
for _ in range(M):
  if j >= As[-1-cnt]:
    i = j>>1
  else:
    i = As[-1-cnt]>>1
    
  j = i
  
  if i < As[-1-cnt-1]:
    cnt += 1
    bisect.insort_left(As,i)

if j > As[-1-cnt-1]:
  bisect.insort_left(As,j)
  cnt += 1

print(sum(As[:-cnt]))

Buggy submission (verdict: Runtime Error):
import bisect

N, M = map(int, input().split(" "))
As = list(map(int, input().split(" ")))
As = sorted(As)
cnt = 0
j = 0
for _ in range(M):
  if j >= As[-1-cnt]:
    i = j>>1
  else:
    i = As[-1-cnt]>>1
    
  j = i
  
  if i < As[-1-cnt-1]:
    cnt += 1
    bisect.insort_left(As,i)

if j > As[-1-cnt-1]:
  bisect.insort_left(As,j)

print(sum(As[:-cnt]))
Problem p02915 (python)

Fixed submission:
n = int(input())
print(n**3)

Buggy submission (verdict: Runtime Error):
import bisect

n = int(input())
P = list(map(int, input().split(" ")))
sp = sorted(P, reverse=True)
bi = []
bisect.insort(bi,P.index(sp[0]))
C = 0
lc = 0
rc = 0
C1 = 0
for j in sp[1:]:
  i = P.index(j)
  #bisect.insort(bi,i)
  l = bisect.bisect_left(bi,i)
  if l == 0:
    lc = i + 1
    if len(bi) == 1:
      rc = n - bi[0]
    else:
      rc = bi[l+1] - bi[l]
    C1 = lc*rc
  elif l == len(bi):
    if len(bi) == 1:
      lc = bi[0] + 1
    else:
      lc = bi[l-1] - bi[l-2]
    rc = n - i
    C1 = lc*rc
  else: 
    if len(bi) == 2:
      lc = bi[0] + 1
      rc = bi[1] - i
      C1 = lc*rc
      lc = i - bi[0]
      rc = n - bi[1]
      C1 += lc*rc
    elif l == 1:
      lc = bi[0] + 1
      rc = bi[1] - i
      C1 = lc*rc
      lc = i - bi[0]
      rc = bi[2] - bi[1]
      C1 += lc*rc
    elif l == len(bi) - 1:
      lc = bi[l-1] - bi[l-2]
      rc = bi[l] - i
      C1 = lc*rc
      lc = i - bi[l-1]
      rc = n - bi[l]
      C1 += lc*rc
    else:
      lc = bi[l-1] - bi[l-2]
      rc = bi[l] - i
      C1 = lc*rc
      lc = i - bi[l-1]
      rc = bi[l+1] - bi[l]
      C1 += lc*rc
  C += (P[i]*C1)
  bisect.insort(bi,i)
  
print(C)
Problem p02925 (python)

Fixed submission:
from collections import deque
 
N = int(input())
As = [[]]
iset = [0]*(N+1)
for _ in range(N):
  As.append(list(map(int, input().split())))

cnt = 0
cset = set([i for i in range(1,N+1)])
while len(cset) > 0:
  cnt += 1
  fset = set()
  nex = set()
  f = 1
  for i in cset:
    if i not in fset:
      vis = As[i][iset[i]]
      if As[vis][iset[vis]] == i and vis not in fset:
        iset[i] += 1
        iset[vis] += 1
        fset.add(i)
        fset.add(vis)
        if iset[i] < N-1:
          nex.add(i)
        if iset[vis] < N-1:
          nex.add(vis)
        f = 0
  cset = nex
  if f == 1:
    print('-1')
    exit()
    
print(cnt)

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

arr = {(i,j):set([]) for i in range(1,N+1) for j in range(i+1,N+1)}
dic = {(i,j):0 for i in range(1,N+1) for j in range(i+1,N+1)}
used = {(i,j):0 for i in range(1,N+1) for j in range(i+1,N+1)}
visited = {(i,j):0 for i in range(1,N+1) for j in range(i+1,N+1)}
rlt = {(i,j):0 for i in range(1,N+1) for j in range(i+1,N+1)}

def dfs(t):
  for u in arr[t]:
    if visited[u] == 1 and used[u] == 0:
      return -1
    rlt[u] = max(rlt[u], rlt[t]+1)
    if visited[u] == 0:
      visited[u] = 1
      dfs(u)
  used[t] = 1
  return 0

for i in range(1,N+1):
  As = map(int, input().split())
  b = 0
  for a in As:
    if b > 0:
      if i < a and i < b:
        arr[(i,b)].add((i,a))
        dic[(i,a)] += 1
      elif i > a and i < b:
        arr[(i,b)].add((a,i))
        dic[(a,i)] += 1
      elif i < a and i > b:
        arr[(b,i)].add((i,a))
        dic[(i,a)] += 1
      elif i > a and i > b:
        arr[(b,i)].add((a,i))
        dic[(a,i)] += 1
    b = a
    
cnt = N+1
for t in rlt:
  cnt = min(cnt, dic[t])
if cnt > 0:
  print(-1)
  exit()
  
cnt = 0
for t in rlt:
  if dic[t] > 0:
    continue
  rlt[t] = 1
  r = dfs(t)
  if r == -1:
    print(-1)
    exit()
        
for t in rlt:
  cnt = max(rlt[t], cnt)
print(cnt)
Problem p02933 (python)

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

if a < 3200:
  print('red')
else:
  print(s)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split(" "))
 
ns= [list(map(int, input().split(" ")))  for _ in range(N-1)]
 
flags = [False]*N
dic = [[] for _ in range(N)]
rlt = [0]*N
 
for i in range(N-1):
  dic[ns[i][1]-1] += [ns[i][0]-1]
  dic[ns[i][0]-1] += [ns[i][1]-1]
  
for p, x in (map(int, input().split()) for _ in range(Q)):
  rlt[p - 1] += x
 
que = [0]
while len(que):
  a = que.pop(0)
  flags[a] = True
  for e in dic[a]:
    if flags[e]:
      continue
    else:
      rlt[e] += rlt[a]
      que.append(e)
    
print(" ".join(map(str, rlt)))
Problem p02831 (python)

Fixed submission:
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
import fractions

def main():
    a,b = map(int, input().split())

    print(a*b//fractions.gcd(a, b))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

def main():
    a,b = map(int, input().split())

    print(a*b//math.gcd(a, b))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

def main():
    a,b = map(int, input().split())

    print(a*b//math.gcd(a, b))


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

Fixed submission:
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

def main():
    A = list(map(int, input().split()))

    if sum(A) >= 22:
        print('bust')
    else:
        print('win')


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

def main():
    A = list(map(int, input().split()))

    if sum(A) => 22:
        print('bust')
    else:
        print('win')


if __name__ == '__main__':
    main()