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

Fixed submission:
A,B = map(int,input().split())
print(A*B-(A+(B-1)))

Buggy submission (verdict: Runtime Error):
N = int(input())
i = 0
j = 0
count = 0
flag = 0

for i in range(1, N + 1, 2):
    count = 0
    for j in range(1,i + 1):
        if i % j == 0:
            count += 1
    else:
        if count == 8:
            flag += 1
else:
    print(flag)
Problem p03292 (python)

Fixed submission:
x =list(map(int,input().split()))

x.sort()
print((x[1]-x[0])+(x[2]-x[1]))

Buggy submission (verdict: Runtime Error):
S = [i for i in input()]
T = [j for j in input()] 

x = sorted(S)
y = sorted(T)
k = None

if x == y:
  for i in range(len(S)):
    O = S.copy()
    S.pop()
    S.insert(0,O[-1])
    if S == T:
      print("Yes")
      break
  else:
    print("NO")
else:
  print("No")
Problem p03324 (python)

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

if N == 100:
  print(100**D*101)
else:
  print(100**D*N)

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

if N = 100:
  print(100**D*101)
else:
  print(100**D*N)
Problem p03328 (python)

Fixed submission:
a,b=map(int,input().split())
total=0
for i in range(1,b-a+1):
  total+=i
print(total-b)

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
t = b - a
n = [1]
x = 1

for i in range(2,999):
  x = i + x
  n.append(x)

else:
  for j in range(0,1000):
    if n[j+1] - n[j] == t:
      break
print(n[j] - a)

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
t = b - a
n = [1]
x = 1

for i in range(2,999):
  x = i + x
  n.append(x)

else:
  for j in range(0,len(n)):
    if n[j+1] - n[j] == t:
      break
print(n[j] - a)

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
t = b - a
n = [1]
x = 1

for i in range(2,999):
  x = i + x
  n.append(x)

else:
  for j in range(0,len(n) + 1):
    if n[j+1] - n[j] == t:
      break
print(n[j] - a)
Problem p03494 (python)

Fixed submission:
N = int(input())
x = list(map(int,input().split()))
count = 0
K = None

while True:
  for j in range(N):
    if x[j] % 2 == 0:
      x[j] /= 2
    else:
      K = 0
      break
  
  else:
    count += 1
  if K==0:
    break

print(count)

Buggy submission (verdict: Runtime Error):
while True:
  for j in range(N):
    if x[j] % 2 == 0:
      x[j] /= 2
    else:
      K = 0
      break
  
  else:
    count += 1
  if K==0:
    break

print(count)
Problem p03632 (python)

Fixed submission:
A,B,C,D  =map(int,input().split())
AB = [str(i) for i in range(A,B+1)]
CD = [str(j) for j in range(C,D+1)]
count = 0

for a in range(101):
  if str(a) in AB and str(a) in CD:
    count += 1
if count == 0:
  print(0)
else:
  print(count-1)

Buggy submission (verdict: Runtime Error):
A,B,C,D  =map(int,input().split())
AB = [str(i) for i in range(A,B+1)]
CD = [str(j) for j in range(C,D+1)]
count = 0

for a in range(101):
  if str(a) in AB and str(a) in CD:
    count += 1
if count = 0:
  print(0)
else:
  print(count-1)
Problem p03729 (python)

Fixed submission:
a,b,c = map(str,input().split())
if a[-1]==b[0] and b[-1]==c[0]:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
if a[-1]==b[0] and b[-1]==c[0]:
  print("YES")
else:
  print("NO")
Problem p03844 (python)

Fixed submission:
A,B,C=map(str,input().split())
if B=="+":
  print(int(A)+int(C))
else:
  print(int(A)-int(C))

Buggy submission (verdict: Runtime Error):
A,B,C=map(str,input().split())
if B=="+":
  print(A+C)
else:
  print(A-C)
Problem p04029 (python)

Fixed submission:
x=[i for i in range(1,int(input())+1)]
print(sum(x))

Buggy submission (verdict: Runtime Error):
x=[i for i in range(1,input()+1)]
print(x)

Buggy submission (verdict: Runtime Error):
x=[i for i in range(input())]
print(sum(x))
Problem p02616 (python)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

if max(a) < 0:
    a.sort()
    ans = 1
    if k % 2 == 0:
        for e in a[:k]:
            ans *= e
            ans %= mod
    else:
        for e in a[-k:]:
            ans *= e
            ans %= mod

    print(ans)

elif k == n:
    ans = 1
    for e in a:
        ans *= e
        ans %= mod

    print(ans)

else:
    neg = []
    pos = []
    for e in a:
        if e < 0:
            neg.append(e)
        else:
            pos.append(e)

    neg.sort()
    pos.sort(reverse=True)

    ans = 1
    if k % 2:
        ans *= pos.pop(0)
        k -= 1

    nums = [e1 * e2 for e1, e2 in zip(neg[::2], neg[1::2])]
    nums += [e1 * e2 for e1, e2 in zip(pos[::2], pos[1::2])]

    nums.sort(reverse=True)
    for e in nums[:k//2]:
        ans *= e
        ans %= mod

    print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

if max(a) < 0:
    a.sort()
    ans = 1
    if k % 2 == 0:
        for e in a[:k]:
            ans *= e
            ans %= mod
    else:
        for e in a[-k:]:
            ans *= e
            ans %= mod

    print(ans)

else:
    neg = []
    pos = []
    for e in a:
        if e < 0:
            neg.append(e)
        else:
            pos.append(e)

    neg.sort()
    pos.sort(reverse=True)

    ans = 1
    if k % 2:
        ans *= pos.pop(0)
        k -= 1

    nums = [e1 * e2 for e1, e2 in zip(neg[::2], neg[1::2])]
    nums += [e1 * e2 for e1, e2 in zip(pos[::2], pos[1::2])]
    if len(neg) % 2:
        nums += neg[-1]
    if len(pos) % 2:
        nums += pos[-1]

    nums.sort(reverse=True)
    for e in nums[:k//2]:
        ans *= e
        ans %= mod

    print(ans)
Problem p02632 (python)

Fixed submission:
k = int(input())
s = input()
mod = 10 ** 9 + 7

MAX = 2 * 10 ** 6

fact = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    fact[i] = (fact[i-1] * i) % mod

inv = [1] * (MAX + 1)
for i in range(2, MAX + 1):
    inv[i] = inv[mod % i] * (mod - mod // i) % mod

fact_inv = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    fact_inv[i] = fact_inv[i-1] * inv[i] % mod


def comb(n, k):
    if n < k:
        return 0
    return fact[n] * fact_inv[n-k] * fact_inv[k] % mod


ln = len(s)

ans = 0
pow25 = 1
pow26 = pow(26, k, mod)
inv26 = pow(26, mod - 2, mod)
for i in range(ln, k + ln + 1):
    ans += pow25 * pow26 % mod * comb(i - 1, ln - 1) % mod
    ans %= mod
    pow25 *= 25
    pow25 %= mod
    pow26 *= inv26
    pow26 %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
k = int(input())
s = input()
mod = 10 ** 9 + 7

MAX = 2 * 10 ** 6

fact = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    fact[i] = (fact[i-1] * i) % mod

inv = [1] * (MAX + 1)
for i in range(2, MAX + 1):
    inv[i] = inv[mod % i] * (mod - mod // i) % mod

fact_inv = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    fact_inv[i] = fact_inv[i-1] * inv[i] % mod


def comb(n, k):
    if n < k:
        return 0
    return fact[n] * fact_inv[n-k] * fact_inv[k] % mod


ln = len(s)

ans = 0
pow25 = 1
pow26 = pow(26, k, mod)
inv26 = pow(26, mod - 2, mod)
for i in range(ln, k + ln + 1):
    raise Exception
    ans += pow25 * pow26 % mod * comb(i - 1, ln - 1) % mod
    ans %= mod
    pow25 *= 25
    pow25 %= mod
    pow26 *= inv26
    pow26 %= mod

print(ans)
Problem p02642 (python)

Fixed submission:
from time import time


def fact(x):
    i = 1
    while i * i <= x:
        if x % i == 0:
            yield i
            yield x // i
        i += 1


def main():
    n = int(input())
    a = tuple(map(int, input().split()))
    now = time()

    c = [0] * (max(a) + 1)

    for e in a:
        c[e] += 1

    ans = n
    for e in a:
        c[e] -= 1
        for fct in fact(e):
            if c[fct]:
                ans -= 1
                break

        if time() - now >= 1.8:
            print(n)
            exit()

        c[e] += 1

    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from numba import njit


@njit(cache=True)
def fact(x):
    i = 1
    while i * i <= x:
        if x % i == 0:
            yield i
            yield x // i
        i += 1


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

    c = [0] * (max(a) + 1)

    for e in a:
        c[e] += 1

    ans = n
    for e in a:
        c[e] -= 1
        for fct in fact(e):
            if c[fct]:
                ans -= 1
                break

        c[e] += 1

    print(ans)


if __name__ == "__main__":
    main()
Problem p02692 (python)

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

n, a, b, c = map(int, input().split())
s = [input() for _ in range(n)]

ans = []

d = {"A": a, "B": b, "C": c}


def dfs(i):
    if min(d.values()) < 0:
        return

    if i == n:
        print("Yes")
        print(*ans, sep="\n")
        exit()

    k1, k2 = s[i]

    d[k1] += 1
    d[k2] -= 1
    ans.append(k1)
    dfs(i+1)
    d[k1] -= 1
    d[k2] += 1
    ans.pop()

    d[k2] += 1
    d[k1] -= 1
    ans.append(k2)
    dfs(i+1)
    d[k2] -= 1
    d[k1] += 1
    ans.pop()


dfs(0)

print("No")

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

a = min(a, 1)
b = min(b, 1)
c = min(c, 1)

ans = []

d = {"A": a, "B": b, "C": c}


def dfs(i):
    if min(d.values()) < 0:
        return

    if i == n:
        print("Yes")
        print(*ans, sep="\n")
        exit()

    k1, k2 = s[i]

    d[k1] += 1
    d[k2] -= 1
    ans.append(k1)
    dfs(i+1)
    d[k1] -= 1
    d[k2] += 1
    ans.pop()

    d[k2] += 1
    d[k1] -= 1
    ans.append(k2)
    dfs(i+1)
    d[k2] -= 1
    d[k1] += 1
    ans.pop()


dfs(0)

print("No")
Problem p02758 (python)

Fixed submission:
def main():
    n = int(input())
    xd = [map(int, input().split()) for _ in range(n)]
    mod = 998244353
    INF = 10 ** 10

    xx = [(x, x + d, i) for i, (x, d) in enumerate(xd, 1)]
    xx.sort()
    adj = [[] for _ in range(n + 1)]
    stack = [(INF, 0)]
    for l, r, i in xx:
        while stack[-1][0] <= l:
            stack.pop()

        ip = stack[-1][1]
        adj[ip].append(i)
        stack.append((r, i))

    stack2 = [0]
    d = [-1] * (n + 1)
    d[0] = 0
    c = [[] for _ in range(n + 1)]
    order = []
    while stack2:
        u = stack2.pop()
        order.append(u)
        for v in adj[u]:
            if d[v] == -1:
                d[v] = d[u] + 1
                c[u].append(v)
                stack2.append(v)

    dp = [1] * (n + 1)
    for u in order[::-1]:
        for v in c[u]:
            dp[u] *= dp[v]
            dp[u] %= mod

        dp[u] += 1
        dp[u] %= mod

    ans = dp[0] - 1
    ans %= mod
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

def main():
    n = int(input())
    xd = [map(int, input().split()) for _ in range(n)]
    mod = 998244353
    INF = 10 ** 10

    xx = [(x, x + d, i) for i, (x, d) in enumerate(xd, 1)]
    xx.sort()
    c = [[] for _ in range(n + 1)]
    stack = [(INF, 0)]
    for l, r, i in xx:
        while stack[-1][0] <= l:
            stack.pop()

        ip = stack[-1][1]
        c[ip].append(i)
        stack.append((r, i))

    order = map(itemgetter(2), xx)

    dp = [1] * (n + 1)
    for u in order[::-1]:
        for v in c[u]:
            dp[u] *= dp[v]
            dp[u] %= mod

        dp[u] += 1
        dp[u] %= mod

    ans = dp[0] - 1
    ans %= mod
    print(ans)


if __name__ == "__main__":
    main()
Problem p02774 (python)

Fixed submission:
def comb(li):
    return len(li) * (len(li) - 1) // 2


def count_large(x, li):
    cnt = 0
    j = 0
    for e in li:
        cnt -= e * e >= x
        while li[j-1] * e >= x:
            j -= 1

        cnt -= j

    cnt //= 2
    return cnt


n, k = map(int, input().split())
a = list(map(int, input().split()))
INF = 10 ** 20

neg = []
pos = []

for e in a:
    if e > 0:
        pos.append(e)
    elif e < 0:
        neg.append(e)

# k-th is negative
if k <= len(pos) * len(neg):
    neg.sort()
    neg.append(0)
    pos.sort()

    lb = -10 ** 18 - 1
    ub = 0
    while ub - lb > 1:
        m = (lb + ub) // 2
        j = -1
        cnt = 0
        for e in pos:
            while neg[j+1] * e <= m:
                j += 1

            cnt += j + 1

        if cnt >= k:
            ub = m
        else:
            lb = m

    print(ub)

# k-th is positive
elif k >= n * (n - 1) // 2 - comb(pos) - comb(neg) + 1:
    neg = [-e for e in neg]
    neg.append(0)
    neg.sort()
    pos.append(0)
    pos.sort()

    lb = 1
    ub = 10 ** 18 + 1
    while ub - lb > 1:
        m = (lb + ub) // 2
        cnt = count_large(m, neg) + count_large(m, pos)
        if cnt >= n * (n - 1) // 2 - k + 1:
            lb = m
        else:
            ub = m

    print(lb)


# k-th is 0
else:
    print(0)

Buggy submission (verdict: Runtime Error):
def comb(li):
    return len(li) * (len(li) - 1) // 2


def count_small(x, li):
    cnt = 0
    j = len(li)
    for i, e in enumerate(li[1:], 1):
        while li[j-1] * e > x:
            j -= 1
        cnt += min(i - 1, j - 1)

    return cnt


n, k = map(int, input().split())
a = list(map(int, input().split()))
INF = 10 ** 20

neg = []
pos = []

for e in a:
    if e > 0:
        pos.append(e)
    elif e < 0:
        neg.append(e)

# k-th is negative
if k <= len(pos) * len(neg):
    neg.sort()
    neg.append(0)
    pos.sort()

    lb = -10 ** 18 - 1
    ub = 0
    while ub - lb > 1:
        m = (lb + ub) // 2
        j = -1
        cnt = 0
        for e in pos:
            while neg[j+1] * e <= m:
                j += 1

            cnt += j + 1

        if cnt >= k:
            ub = m
        else:
            lb = m

    print(ub)

# k-th is positive
elif k >= n - comb(pos) - comb(neg) + 1:
    raise Exception
    k -= len(pos) * len(neg)
    cnt0 = a.count(0)
    k -= cnt0 * (n - 1) - cnt0 * (cnt0 - 1) // 2
    neg = [-e for e in neg]
    neg.sort()
    neg.insert(0, 0)
    pos.sort()
    pos.insert(0, 0)

    lb = 0
    ub = 10 ** 18
    while ub - lb > 1:
        m = (lb + ub) // 2
        cnt = count_small(m, neg) + count_small(m, pos)
        if cnt >= k:
            ub = m
        else:
            lb = m

    print(ub)

# k-th is 0
else:
    print(0)
Problem p02814 (python)

Fixed submission:
from fractions import gcd


def cnt_div2(x):
    ret = 0
    while x % 2 == 0:
        ret += 1
        x //= 2

    return ret


n, m = map(int, input().split())
a = list(map(int, input().split()))

aa = [e // 2 for e in a]

cnt = cnt_div2(aa[0])
for e in aa:
    if cnt_div2(e) != cnt:
        print(0)
        exit()


def lcm(x, y):
    return x // gcd(x, y) * y


c = 1
for e in aa:
    c = lcm(c, e)

ans = m // c
print((ans + 1) // 2)

Buggy submission (verdict: Runtime Error):
from math import sqrt, floor

n, m = map(int, input().split())
a = list(map(int, input().split()))


def cnt_div2(x):
    ret = 0
    while x % 2 == 0:
        x //= 2
        ret += 1

    return ret, x


def e_sieve(x):
    li = list(range(2, x + 1))
    primes = []
    while li[0] <= floor(sqrt(x)):
        prime = li[0]
        primes.append(prime)
        li = [e for e in li if e % prime != 0]

    primes += li

    return primes


cnt, _ = cnt_div2(a[0])
for e in a:
    if cnt_div2(e)[0] != cnt:
        print(0)
        exit()

for i, e in enumerate(a):
    a[i] //= 2 ** cnt

primes = e_sieve(max(a))
primes.pop(0)

fact_cnt = [0] * len(primes)

for e in a:
    for i, p in enumerate(primes):
        cnt = 0
        while e % p == 0:
            e //= p
            cnt += 1
        fact_cnt[i] = max(fact_cnt[i], cnt)

lcm = 1
for p, f in zip(primes, fact_cnt):
    lcm *= p ** f

ans = (m // lcm + 1) // 2
print(ans)
Problem p02821 (python)

Fixed submission:
from itertools import accumulate

n, m = map(int, input().split())
a = list(map(int, input().split()))

a.sort(reverse=True)
a_acm = list(accumulate(a))

a_cnt = [0] * (10 ** 6 + 1)
for e in a:
    a_cnt[e] += 1

acm = list(accumulate(a_cnt))


def count_handshake(x):
    ret = 0
    for e in a:
        if x - e - 1 >= 0:
            cnt = acm[-1] - acm[x-e-1]
        else:
            cnt = n

        ret += cnt

    return ret


left = 0
right = 10 ** 6

while right - left > 1:
    mid = (left + right) // 2
    if count_handshake(mid) >= m:
        left = mid
    else:
        right = mid

ans = 0
handshake_cnt = 0
for e in a:
    if left - e - 1 >= 0:
        cnt = n - acm[left-e-1]
    else:
        cnt = n

    if cnt > 0:
        ans += e * cnt + a_acm[cnt-1]
        handshake_cnt += cnt

if handshake_cnt > m:
    ans -= left * (handshake_cnt - m)

print(ans)

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

n, m = map(int, input().split())
a = list(map(int, input().split()))
MAX = 10 ** 5

scores = [0] * (MAX + 1)
for e in a:
    scores[e] += 1

acc = list(accumulate(scores))


def f(x):
    cnt = 0
    for e in a:
        cnt += n - acc[max(0, x - e - 1)]

    return cnt


l = 0
r = 2 * MAX
while r - l > 1:
    mid = (l + r) // 2
    if f(mid) >= m:
        l = mid
    else:
        r = mid

scores_sum = [i * e for i, e in enumerate(scores)]
acc_sum = list(accumulate(scores_sum))
sm = sum(a)
ans = 0
cnt_sum = 0
for e in sorted(a, reverse=True):
    i = max(0, l - e - 1)
    cnt = n - acc[i]
    ans += e * cnt + sm - acc_sum[i]
    cnt_sum += cnt

ans -= (cnt_sum - m) * l

print(ans)
Problem p02824 (python)

Fixed submission:
n, m, v, p = map(int, input().split())
a = list(map(int, input().split()))

a.sort(reverse=True)


def can_be_used(x):
    # x: 0-index
    if x < p:
        return True

    if a[x] + m < a[p-1]:
        return False

    vote_max = (p - 1 + n - x) * m
    for i in range(p-1, x):
        vote_max += a[x] + m - a[i]

    if vote_max < m * v:
        return False

    return True


l = 0
r = n

while r - l > 1:
    mid = (l + r) // 2

    if can_be_used(mid):
        l = mid
    else:
        r = mid

ans = l + 1
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
from collections import Counter
from math import ceil

n, m, v, p = map(int, input().split())
a = list(map(int, input().split()))

a.sort(reverse=True)
acm = list(accumulate(a))
c = Counter(a)
c = list(c.values())
#print(c)
always_ok = a[p-1]
cnt = 0
j = 0
prev = -1

for i, e in enumerate(a):
    if e != prev:
        cnt += c[j]
        j += 1
        prev = e
    if e >= always_ok:
        continue

    if n - i + p - 1 >= v:
        if e + m >= always_ok:
            continue
        else:
            #print(i, e, "break")
            break

    cnt -= c[j-1]
    #print(i, e)
    left = v - (n - i + p - 1)
    #print(left)
    sm = acm[i-1] - acm[cnt-1]
    #print(sm)
    mx = max(a[p-1], ceil((sm + left * m) / (i - cnt + 1)))
    #print(mx)
    cnt += c[j-1]
    if mx > e + m:
        break

cnt = 0
for ae in a:
    if ae == e:
        break
    cnt += 1

print(cnt)
Problem p02839 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H,W = map(int,readline().split())
A = [list(map(int,readline().split())) for _ in range(H)]
B = [list(map(int,readline().split())) for _ in range(H)]

X = (H + W) * 80
# X点持った状態から始める
dp = [[0] * W for _ in range(H)]
d = abs(A[0][0] - B[0][0])
dp[0][0] = (1 << (X - d))
for h in range(H):
    for w,(a,b) in enumerate(zip(A[h],B[h])):
        if h == w == 0:
            continue
        d = abs(a - b)
        x = 0
        if h != 0:
            x |= (dp[h-1][w] << d) 
            x |= (dp[h-1][w] >> d)
        if w != 0:
            x |= (dp[h][w-1] << d) 
            x |= (dp[h][w-1] >> d)
        dp[h][w] = x

dp = dp[-1][-1]

B = bin(dp)[2:]
can_make = [i - X for i,b in enumerate(B[::-1]) if b == '1']

answer = min(x if x >= 0 else -x for x in can_make)
print(answer)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]

x = (h + w) * 80

dp = [[0] * w for _ in range(h)]
d = abs(a[0][0] - b[0][0])
dp[0][0] = 1 << (x - d)

for i in range(h):
    for j, (ae, be) in enumerate(zip(a[i], b[i])):
        if h == w == 0:
            continue

        d = abs(ae - be)
        bt = 0
        if i != 0:
            bt |= dp[i-1][j] << d
            bt |= dp[i-1][j] >> d

        if j != 0:
            bt |= dp[i][j-1] << d
            bt |= dp[i][j-1] >> d

        dp[i][j] = bt

dp = dp[-1][-1]

b = bin(dp)[2:]
can_make = [i - x for i, be in enumerate(b[::-1]) if be == "1"]

ans = min(x if x >= 0 else -x for x in can_make)
print(ans)
Problem p02850 (python)

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 6)

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n - 1)]

adj = defaultdict(list)
for i, (a, b) in enumerate(ab):
	a -= 1
	b -= 1
	adj[a].append((b, i))
	adj[b].append((a, i))

k = max([len(li) for li in adj.values()])
print(k)

ans = [-1] * (n - 1)

def dfs(u, p_col):
	col = 1
	for v, i in adj[u]:
		if ans[i] != -1:
			continue
		if col == p_col:
			col += 1
		ans[i] = col
		dfs(v, col)
		col += 1


dfs(0, -1)

print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, deque

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n - 1)]

adj = defaultdict(list)
for i, (a, b) in enumerate(ab):
	a -= 1
	b -= 1
	adj[a].append((b, i))
	adj[b].append((a, i))

k = max([len(li) for li in adj.values()])
print(k)

ans = [-1] * (n - 1)

def dfs(u, p_col):
	col = 1
	for v, i in adj[u]:
		if ans[i] != -1:
			continue
		if col == p_col:
			col += 1
		ans[i] = col
		dfs(v, col)
		col += 1


dfs(0, -1)

print(*ans, sep="\n")
Problem p02882 (python)

Fixed submission:
from math import atan, degrees


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

    full = a * a * b
    half = full * 0.5

    if x <= half:
        s = x / a
        ans = 90 - degrees(atan(2 * s / b ** 2))

    else:
        s = (full - x) / a
        if s != 0:
            ans = 90 - degrees(atan(a ** 2 / (2 * s)))
        else:
            ans = 0

    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from math import atan, degrees


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

    full = a * a * b
    half = full * 0.5

    if x <= half:
        s = x / a
        ans = 90 - degrees(atan(2 * s / b ** 2))

    else:
        s = (full - x) / a
        ans = 90 - degrees(atan(a ** 2 / (2 * s)))

    print(ans)


if __name__ == "__main__":
    main()
Problem p02913 (python)

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

l = len(s)

dp = [[0] * (l + 1) for _ in range(l + 1)]
dp[0][0] = 1

ans = 0
for i, ei in enumerate(s, 1):
    for j, ej in enumerate(s[i:], i+1):
        if ei == ej:
            dp[i][j] = min(dp[i-1][j-1] + 1, j - i)
            ans = max(ans, dp[i][j])

print(ans)

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

n = int(input())
s = np.array(list(input()))

l = s.size

dp = np.zeros(l, dtype=np.int16)
ans = 0
for i, e in enumerate(s, 1):
    dp_prev = dp[:]
    mx = np.arange(1, l + 1) - i
    idx = np.hstack([np.full(i, False), s[i:] == e])
    idx_prev = np.hstack([np.full(i-1, False), s[i:] == e, [False]])
    dp = np.zeros(l, dtype=np.int16)
    dp[idx] = np.minimum(dp_prev[idx_prev] + 1, mx[idx])
    ans = max(ans, dp.max())

print(ans)
Problem p02934 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

div = 0
for i in range(n):
    div += 1 / a[i]
print(1 / div)

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

div = 0
for i in range(n):
    div += a / a[i]
print(1 / div)