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

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

a.sort()
am = a[-1]

memo = [0] * (am+1)

for ai in a:
    memo[ai] = 1

p = -1

for ai in a:
    if ai == p:
        memo[ai] = 0
        continue
    for j in range(2, am // ai + 1):
        memo[ai * j] = 0
    p = ai

print(sum(memo))

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

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

dic = Counter(a)

ans = 0

memo = {}

def seachPrimeNum(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

primeNum = set(seachPrimeNum(10**6))

for ai in a:
    cnt = 0
    f = 1
    if ai not in memo:
        if ai not in primeNum:
            for i in range(1, int(math.sqrt(ai))+1):
                if ai % i == 0:
                    d = i
                    if d in dic:
                        cnt += dic[d]
                    if d == ai:
                        cnt -= 1
                    if cnt > 0:
                        f = 0
                        break
                    if i != ai // i:
                        d = ai // i
                        if d in dic:
                            cnt += dic[d]
                        if d == ai:
                            cnt -= 1
                        if cnt > 0:
                            f = 0
                            break
    else:
        f = memo[ai]
    ans += f
    memo[ai] = f

print(ans)
Problem p02678 (python)

Fixed submission:
from collections import deque

n, m = map(int, input().split())
E = [[] for i in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

INF = 2 * m

dists = [INF for i in range(n)]

def bfs(cur, pre, dist):
    stack = deque([[cur, pre, dist]])
    while stack:
        cur, pre, dist = stack.popleft()
        if dist < dists[cur]:
            dists[cur] = dist
            for e in E[cur]:
                if e != pre:
                    stack.append([e, cur, dist + 1])
bfs(0, -1, 0)

print('Yes')

for i in range(1,n):
    di = dists[i]
    for e in E[i]:
        if di - 1 == dists[e]:
            print(e+1)
            break

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

n, m = map(int, input().split())
E = [[] for i in range(m)]

for i in range(m):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

INF = 2 * m

dists = [INF for i in range(n)]

def bfs(cur, pre, dist):
    global dists
    stack = deque([[cur, pre, dist]])
    while stack:
        cur, pre, dist = stack.popleft()
        if dist < dists[cur]:
            dists[cur] = dist
            for e in E[cur]:
                if e != pre:
                    stack.append([e, cur, dist + 1])
bfs(0, -1, 0)

print('Yes')

for i in range(1,n):
    di = dists[i]
    for e in E[i]:
        if di - 1 == dists[e]:
            print(e+1)
            break

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

n, m = map(int, input().split())
E = [[] for i in range(m)]

for i in range(m):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

INF = 2 * m

dists = [INF for i in range(n)]

def bfs(cur, pre, dist):
    stack = deque([[cur, pre, dist]])
    while stack:
        cur, pre, dist = stack.popleft()
        if dist < dists[cur]:
            dists[cur] = dist
            for e in E[cur]:
                if e != pre:
                    stack.append([e, cur, dist + 1])
bfs(0, -1, 0)

print('Yes')

# for i in range(1,n):
#     di = dists[i]
#     for e in E[i]:
#         if di - 1 == dists[e]:
#             print(e+1)
#             break

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

n, m = map(int, input().split())
E = [[] for i in range(m)]

for i in range(m):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

INF = 2 * m

dists = [INF for i in range(n)]

def bfs(cur, pre, dist):
    stack = deque([[cur, pre, dist]])
    while stack:
        cur, pre, dist = stack.popleft()
        if dist < dists[cur]:
            dists[cur] = dist
            for e in E[cur]:
                if e != pre:
                    stack.append([e, cur, dist + 1])
bfs(0, -1, 0)

print('Yes')

for i in range(1,n):
    di = dists[i]
    for e in E[i]:
        if di - 1 == dists[e]:
            print(e+1)
            break
Problem p02697 (python)

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

a = (n - 1) // 2
d = 1
memo = set([])
cnt = 0
for i in range(m):

    if (n - d in memo) or (2*d == n):
        cnt += 1
        d += 1
    memo.add(d)
    if cnt > 1 or a < 1 or a+d > n:
        print(1/0)
    print(a, a+d)
    a -= 1
    d += 2

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


m = (n-1) // 2
a = (n - 1) // 2
d = 1
memo = set([])
cnt = 0
for i in range(m):

    if (n - d in memo) or (d * 2 == n)):
        cnt += 1
        d += 1
    memo.add(d)
    if cnt > 1 or a < 1 or a+d > n:
        print(1/0)
    print(a, a+d)
    a -= 1
    d += 2

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

if n 

m = (n-1) // 2
a = (n - 1) // 2
d = 1
memo = set([])
cnt = 0
for i in range(m):

    if n - d in memo or d * 2 == n:
        cnt += 1
        d += 1
    memo.add(d)
    if cnt > 1 or a < 1 or a+d > n:
        print(1/0)
    print(a, a+d)
    a -= 1
    d += 2

Buggy submission (verdict: Runtime Error):
n, m  = map(int, input().split())
a = n // 2
d = 1
memo = []
for i in range(m):
    for mi in memo:
        if d + mi == n:
            print(1 / 0)
    memo.append(d)
    print(a, a+d)
    a -= 1
    d += 2
Problem p02745 (python)

Fixed submission:
a = input()
b = input()
c = input()

def match(c1, c2):
    return c1 == '?' or c2 == '?' or c1 == c2

M = 2000

ab, ac, bc = [], [], []
ab_append = ab.append
ac_append = ac.append
bc_append = bc.append

for _  in range(10000):
    ab_append(0)
    ac_append(0)
    bc_append(0)

for _  in range(10000):
    bc_append(0)

A, B, C = len(a), len(b), len(c)
for i in range(A):
    for j in range(B):
        if not match(a[i], b[j]):
            ab[i-j+5000] = 1
for i in range(A):
    for j in range(C):
        if not match(a[i], c[j]):
            ac[i-j+5000] = 1
for i in range(B):
    for j in range(C):
        if not match(b[i], c[j]):
            bc[i-j+10000] = 1

ans = 3 * M

for i in range(-2*M, 2*M):
    for j in range(-2*M, 2* M):
        if ab[i+5000] == 0 and ac[j+5000] == 0 and bc[j-i+10000] == 0:
            L = min(0, min(i, j))
            R = max(A, max(B+i, C+j))
            ans = min(ans, R - L)

print(ans)

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

def match(c1, c2):
    return c1 == '?' or c2 == '?' or c1 == c2

M = 2000

ab, ac, bc = [], [], []
for _  in range(10000):
    ab.append(0)
    ac.append(0)
    bc.append(0)


A, B, C = len(a), len(b), len(c)
for i in range(A):
    for j in range(B):
        if not match(a[i], b[j]):
            ab[i-j+5000] = 1
for i in range(A):
    for j in range(C):
        if not match(a[i], c[j]):
            ac[i-j+5000] = 1
for i in range(B):
    for j in range(C):
        if not match(b[i], c[j]):
            bc[i-j+10000] = 1

ans = 3 * M

for i in range(-2*M, 2*M):
    for j in range(-2*M, 2* M):
        if ab[i+5000] == 0 and ac[j+5000] == 0 and bc[j-i+10000] == 0:
            L = min(0, min(i, j))
            R = max(A, max(B+i, C+j))
            ans = min(ans, R - L)

print(ans)
Problem p02774 (python)

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

a.sort()

def check(t):
    j = n - 1 if t > 0 else 0
    res = 0
    f = 1

    cond = lambda x, t, f:x <= t if f * t > 0 or (t == 0 and f == -1) else x > t
    shift = lambda x, t:x-1 if t > 0 else x+1
    count = lambda x, n, f:n-x if f == 1 else x

    for ai in a:
        if f == 1 and ai > 0:
            f = -1
            j = n - 1 if t > 0 else 0
        if ai:
            while j >= 0 and j < n and cond(ai * a[j], t, f):
                j = shift(j, t)
            if t > 0:
                res += count(j+1, n, f)
            else:
                res += count(j, n, f)
        else:
            if t >= 0:
                res += n
        if ai * ai <= t:
            res -= 1
    return res // 2
            

m = max(max(a)**2, min(a)**2)
l = -m
r = m

while r - l > 1:
    mid = (l + r) // 2
    if check(mid) < k:
        l = mid
    else:
        r = mid

if check(l) == k:
    print(l)
else:
    print(r)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left, bisect_right
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

memo_r = {}
memo_l = {}

def check(t):
    res = 0
    tr = math.sqrt(abs(t))
    for ai in a:
        if ai:
            aj = t // ai
            if ai > 0:
                if not memo_r[aj]:
                    memo_r[aj] = bisect_right(a, aj)
                res += memo_r[aj]
            else:
                if t % ai:
                    if not memo_r[aj]:
                        memo_r[aj] = bisect_right(a, aj)
                    res += n - memo_r[aj]
                else:
                    if not memo_l[aj]:
                        memo_l[aj] = bisect_right(a, aj)
                    res += n - memo_l[aj]
        else:
            if t >= 0:
                res += n
        if t >= 0 and abs(ai) <= tr:
            res -= 1
    return res // 2


m = max(max(a)**2, min(a)**2)
l = -m
r = m

while r - l > 1:
    mid = (l + r) // 2
    if check(mid) < k:
        l = mid
    else:
        r = mid

if check(l) == k:
    print(l)
else:
    print(r)

Buggy submission (verdict: Runtime Error):
import bisect
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l = 0
r = 10 ** 19

def check(mid):
    ret = 0
    for ai in a:
        ret += bisect.bisect_right(a, mid // ai)
    return ret

while True:
    if r - l < 1:
        print(mid)
        break
    mid = (l + r) //2
    if check(mid) < k:
        l = mid
    else:
        r = mid
Problem p02804 (python)

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

N = n+2
P = mod
inv_t = [0]+[1]
for i in range(2,N):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

base = 1
for item in range(n-k+1, n):
    base = (base * item) % mod
for i in range(1, k):
    base = (base * inv_t[i]) % mod
base2 = base

ans = 0
ans2  = 0
top = n - 1
for ai in a:
    if top < k-1:
        break
    if ai > 0:
        ans += base * ai
        ans %= mod
    else:
        ans2 += abs(base * ai)
        ans2 %= mod

    base = base * inv_t[top] * (top - k + 1)  % mod
    top -= 1

top = n-1
for ai in reversed(a):
    if top < k-1:
        break
    if ai > 0:
        ans2 += base2 * ai
        ans2 %= mod
    else:
        ans += abs(base2 * ai)
        ans %= mod
    base2 = base2 * inv_t[top] * (top - k + 1)  % mod
    top -= 1
print((ans - ans2) % mod)

Buggy submission (verdict: Runtime Error):
mod = 10 ** 9 + 7
N = 1000

#逆元テーブル
inv_t = [0]+[1]
for i in range(2, N):
  inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]

#階乗計算
kai = [1, 1]
rev_kai = [1, inv_t[1]]
for i in range(2, N):
	kai.append(kai[-1] * i % mod)
	rev_kai.append(rev_kai[-1] * inv_t[i] % mod)

# コンビネーション計算
def cmb(n, r):
	return kai[n] * rev_kai[r] * rev_kai[n-r] % mod

if __name__ == '__main__':
	n, r = map(int, input().split())
	print(cmb(n, r))
Problem p02807 (python)

Fixed submission:
n = int(input())
x = list(map(int, input().split()))
d = []
for x1, x2 in zip(x, x[1:]):
    d.append(x2 - x1)
mod = 10 ** 9 + 7
base = 1

P = 10**9 + 7
N = n+2
inv_t = [0]+[1]
for i in range(2,N):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

for i in range(1, n):
    base *= i
    base %= mod
ans = 0
b = base
for i, di in enumerate(d):
    ans += (base * di)  % mod
    ans %= mod
    base += b * inv_t[i+2]
    base % mod
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = list(map(int, input().split()))
d = []
for x1, x2 in zip(x, x[1:]):
    d.append(x2 - x1)
mod = 10 ** 9 + 7
base = 1

P = 10**9 + 7
N = n
inv_t = [0]+[1]
for i in range(2,N):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

for i in range(1, n):
    base *= i
    base %= mod
ans = 0
b = base
for i, di in enumerate(d):
    ans += (base * di)  % mod
    ans %= mod
    base += b * inv_t[i+2]
    base % mod
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = list(map(int, input().split()))
d = []
for x1, x2 in zip(x, x[1:]):
    d.append(x2 - x1)
mod = 10 ** 9 + 7
base = 1

P = 10**9 + 7
N = 10000
inv_t = [0]+[1]
for i in range(2,N):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

for i in range(1, n):
    base *= i
    base %= mod
ans = 0
b = base
for i, di in enumerate(d):
    ans += (base * di)  % mod
    ans %= mod
    base += b * inv_t[i+2]
    base % mod
print(ans)
Problem p02814 (python)

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

k = 0
while True:
    if a[0] % 2:
        break
    a[0] = a[0] // 2
    k += 1
base = 2 ** k

f = 0
for i in range(1,n):
    if a[i] % base:
        f = 1
        break
    a[i] = a[i] // base
    if a[i] % 2 == 0:
        f = 1
        break
if f:
    print(0)
else:
    LCM = a[0]
    for ai in a:
        LCM = LCM * ai // fractions.gcd(LCM, ai)
    LCM *= base // 2
    print(((m // LCM) + 1) // 2)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [ai // 2 for ai in a]
b.sort(reverse = True)
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
def lcm(a, b):
    return a * b // max(1, gcd(a, b))
LCM = lcm(b[0], b[1])
for bi in b:
    LCM = lcm(LCM, bi)
if LCM % 2:
    print(((m // LCM) + 1) // 2)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [ai // 2 for ai in a]
b.sort()
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
def lcm(a, b):
    return a * b // gcd(a, b)
LCM = lcm(b[0], b[1])
for bi in b:
    LCM = lcm(LCM, bi)
if LCM % 2:
    print(((m // LCM) + 1) // 2)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [ai // 2 for ai in a]
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
def lcm(a, b):
    return a * b // gcd(a, b)
LCM = lcm(b[0], b[1])
for bi in b:
    LCM = lcm(LCM, bi)
if LCM % 2:
    print(((m // LCM) + 1) // 2)
else:
    print(0)
Problem p02889 (python)

Fixed submission:
import sys
import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix

input = sys.stdin.readline

n, m, l = list(map(int, input().split()))
g_dense = np.zeros((n, n))

for _ in range(m):
    a, b, c = map(int, input().split())
    g_dense[a-1][b-1] = c

q = int(input())
st = [list(map(int, input().split())) for _ in range(q)]

path = shortest_path(g_dense, directed=False)

g_dense = np.zeros((n, n))

for i in range(n):
    for j in range(n):
        if path[i][j] <= l:
            g_dense[i][j] = 1

path = shortest_path(g_dense, directed=False)

INF = float('inf')

for s,t in st:
    ans = path[s-1][t-1]
    if ans == INF:
        print(-1)
    else:
        print(int(ans) - 1)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

input = sys.stdin.readline

cost = []
row = []
col = []

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

for _ in range(m):
    a, b, c = map(int, input().split())
    cost.append(c)
    row.append(a-1)
    col.append(b-1)

q = int(input())
st = [list(map(int, input().split())) for _ in range(q)]

csr = csr_matrix((cost, (row, col)), shape = (n, n))
path = floyd_warshall(csr, directed=False)

cost = []
row = []
col = []

for i in range(n):
    for j in range(n):
        if path[i][j] <= l:
            cost.append(1)
            row.append(i)
            col.append(j) 

csr = csr_matrix((cost, (row, col)), shape = (n, n))
path = shortest_path(csr, directed=False)

INF = float('inf')

for s,t in st:
    ans = path[s-1][t-1]
    if ans == INF:
        print(-1)
    else:
        print(int(ans) - 1)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix

input = sys.stdin.readline

cost = []
row = []
col = []

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

for _ in range(m):
    a, b, c = map(int, input().split())
    cost.append(c)
    row.append(a-1)
    col.append(b-1)

q = int(input())
st = [list(map(int, input().split())) for _ in range(q)]

csr = csr_matrix((cost, (row, col)), shape = (n, n))
path = shortest_path(csr, directed=False)

cost = []
row = []
col = []

for i in range(n):
    for j in range(n):
        if path[i][j] <= l:
            cost.append(1)
            row.append(i)
            col.append(j) 

csr = csr_matrix((cost, (row, col)), shape = (n, n))
path = shortest_path(csr, directed=False)

INF = float('inf')

for s,t in st:
    ans = path[s-1][t-1]
    if ans == INF:
        print(-1)
    else:
        print(int(ans) - 1)
Problem p02946 (python)

Fixed submission:
k, x = map(int, input().split())
print(' '.join([str(i) for i in range(x - k + 1, x + k)]))

Buggy submission (verdict: Runtime Error):
k, x = map(int, input().split())
print(' '.join([x for x in range(x - k + 1, x + k)]))

Buggy submission (verdict: Runtime Error):
k, x = map(int, input().split())
print(' '.join([x in range(x - k + 1, x + k)]))
Problem p02947 (python)

Fixed submission:
n = int(input())
d = {}
for _ in range(n):
  s = input()
  k = tuple(sorted(list(s)))
  if k in d:
    d[k] += 1
  else:
    d[k] = 1
ans = 0
for k in d:
  n = d[k]
  ans += n * (n - 1) // 2
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
d = {}
for _ in range(n):
  s = input()
  k = set(list(s))
  if k in d:
    d[k] += 1
  else:
    d[k] = 1
ans = 0
for k in d:
  n = d[k]
  ans += n * (n - 1) / 2
print(ans)
Problem p02960 (python)

Fixed submission:
s = input()
mod = 10 ** 9 + 7
memo = [0] * (len(s) + 1)
memo[0] = 1
dp = [[0 for _ in range(13)] for __ in range(len(s) + 1)]
dp[0][0] = 1
for i, si in enumerate(s[::-1]):
    memo[i+1] = memo[i] * 10 % 13
    if si == '?':
        for n in range(10):
            a = n * memo[i]
            for j in range(13):
                dp[i+1][(j + a) % 13] = (dp[i+1][(j + a) % 13] + dp[i][j]) % mod
    else:
        a = int(si) * memo[i]
        for j in range(13):
            dp[i+1][(j + a) % 13] = (dp[i+1][(j + a) % 13] + dp[i][j]) % mod
print(dp[len(s)][5])

Buggy submission (verdict: Runtime Error):
s = input()
mod = 10 ** 9 + 7
dp = [[0 for _ in range(13)] for __ in range(len(s) + 1)]
dp[0][0] = 1
for i, si in enumerate(s):
    memo[i+1] = memo[i] * 10 % 13
    if si == '?':
        for n in range(10):
            for j in range(13):
                dp[i+1][(n + j * 10) % 13] += dp[i][j]
    else:
        for j in range(13):
                dp[i+1][(int(si) + j * 10) % 13] += dp[i][j]
    for k in range(13):
      dp[i+1][k] = dp[i+1][k] % mod
print(dp[len(s)][5])
Problem p02985 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10**9)

n, K = map(int, input().split())

mo = 1000000007
ret = 1
E = [[] for _ in range(n)]

def dfs(cur, pre, cand):
    global ret
    ret = (ret % mo * (cand % mo)) % mo
    k = 0
    if pre != -1:
        k = 1
    cand = K - 1 - k
    for e in E[cur]:
        if e != pre:
            dfs(e, cur, cand)
            cand -= 1

for _ in range(n-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

dfs(0, -1, K)
print(ret % mo)

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

mo = 1000000007
ret = 1
E = [[] for _ in range(n)]
def dfs(cur, pre, cand):
    global ret
    ret = ret * cand
    k = 0
    if pre != -1:
        k = 1
    cand = K - 1 - k
    for e in E[cur]:
        if e != pre:
            dfs(e, cur, cand)
            cand -= 1

for _ in range(n-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

dfs(0, -1, K)
print(ret % mo)

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

mo = 1000000007
ret = 1
E = [[] for _ in range(n)]
def dfs(cur, pre, cand):
    global ret
    ret = ret * cand
    k = 0
    if pre != -1:
        k = 1
    cand = K - 1 - k
    for e in E[cur]:
        if e != pre:
            dfs(e, cur, cand)
            cand -= 1

for _ in range(n-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

dfs(0, -1, K)
print(ret % mo)

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

mo = 1000000007
ret = 1
E = [[] for _ in range(n)]
def dfs(cur, pre, cand):
    global ret
    ret = ret * cand
    cand = K - 1 - (pre != -1)
    for e in E[cur]:
        if e != pre:
            dfs(e, cur, cand)
            cand -= 1

for _ in range(n-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

dfs(0, -1, K)
print(ret % mo)

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

mo = 10 ** 10 + 7
ret = 1
E = [[] for _ in range(n)]
def dfs(cur, pre, cand):
    global ret
    ret = ret * cand % mo
    cand = K - 1 - (pre != -1)
    for e in E[cur]:
        if e != pre:
            dfs(e, cur, cand)
            cand -= 1

for _ in range(n-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

dfs(0, -1, K)
print(ret)
Problem p02995 (python)

Fixed submission:
a, b, c, d = map(int, input().split())
ans = b - a + 1

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def calc(d):
    global a, b
    c1 = (a - 1) // d
    c2 = b // d
    return c2 - c1

lcm = c * d // gcd(c, d)
print(ans - calc(c) - calc(d) + calc(lcm))

Buggy submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())
ans = b - a + 1
lcm = c * d // math.gcd(c, d)
def calc(d):
    global a, b
    c1 = (a - 1) // d
    c2 = b // d
    return c2 - c1
print(ans - calc(c) - calc(d) + calc(lcm))
Problem p03000 (python)

Fixed submission:
n, x = map(int, input().split())
l = [0] + list(map(int, input().split()))
d = 0
i = 0
while True:
    if d > x:
        print(i - 1)
        break
    if i == n + 1:
        print(i)
        break
    i += 1
    d += l[i-1]

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
l = list(map(int, input().split()))
d = 0
i = 0
while True:
    if d > x:
        print(i)
        break
    if i == n + 1:
        print(i)
        break
    d += l[i]
    i += 1

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
l = list(map(int, input().split()))
d = 0
i = 0
while True:
    if d > x:
        print(i)
        break
    d += l[i]
    i += 1
Problem p03006 (python)

Fixed submission:
n = int(input())
pos = [list(map(int, input().split())) for _ in range(n)]
d = {}
if n == 1:
  print(1)
else:
  for x, y in pos:
    for nx, ny in pos:
      dx = nx - x
      dy = ny - y
      key = (dx, dy)
      if key == (0, 0):
        continue
      if key in d:
        d[key] += 1
      else:
        d[key] = 1
  print(n - max([d[key] for key in d]))

Buggy submission (verdict: Runtime Error):
n = int(input())
pos = [list(map(int, input().split())) for _ in range(n)]
d = {}
for x, y in pos:
  for nx, ny in pos:
    dx = nx - x
    dy = ny - y
    key = (dx, dy)
    if key == (0, 0):
      continue
    if key in d:
      d[key] += 1
    else:
      d[key] = 1
print(n - max([d[key] for key in d]))