Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7

# 逆元配列の作成
inv = [1] * (2 * (10 ** 5))
for i in range(2, 2 * (10 ** 5)):
    inv[i] = -inv[mod % i] * (mod // i)
    inv[i] %= mod


def comb(n, a):
    res = 1
    for i in range(a):
        res *= n - i  # 分子
        res *= inv[i + 1]  # 分母
        res %= mod  # modで割ったあまり
    return res


ans = pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)

ans %= mod
if ans < 0:
    ans += mod

print(ans)

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

# 逆元配列の作成
inv = [1] * (2 * (10 ** 5)+1)
for i in range(2, 2 * (10 ** 5)+1):
    inv[i] = -inv[mod % i] * (mod // i)
    inv[i] %= mod


def comb(n, a):
    res = 1
    for i in range(a):
        res *= n - i  # 分子
        res *= inv[i + 1]  # 分母
        res %= mod  # modで割ったあまり
    return res


ans = pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)

ans %= mod
if ans < 0:
    ans += mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7


def pow(n):
    if n == 0:
        return 1
    x = pow(n//2)
    x *= x
    if n % 2 == 1:
        x *= 2
    return x


# 逆元配列の作成
inv = [1] * (2 * (10 ** 5))
for i in range(2, 2 * (10 ** 5)):
    inv[i] = -inv[mod % i] * (mod // i)
    inv[i] %= mod


def comb(n, a):
    res = 1
    for i in range(a):
        res *= n - i  # 分子
        res *= inv[i + 1]  # 分母
        res %= mod  # modで割ったあまり
    return res


ans = pow(n) - 1 - comb(n, a) - comb(n, b)

ans %= mod
if ans < 0:
    ans += mod

print(ans)


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

# 逆元配列の作成
inv = [1] * (2 * (10 ** 5)+1)
for i in range(2, 2 * (10 ** 5)+1):
    inv[i] = -inv[mod % i] * (mod // i)
    inv[i] %= mod


def comb(n, a):
    res = 1
    for i in range(a):
        res *= n - i  # 分子
        res *= inv[i + 1]  # 分母
        res %= mod  # modで割ったあまり
    return res


ans = pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)

ans %= mod
if ans < 0:
    ans += mod

print(ans)

Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
total = pow(2, n, mod) - 1

N = 2 * (10 ** 5)
inv = [1] * N
for i in range(2, N):
    inv[i] = -inv[mod % i] * (mod // i)
    inv[i] %= mod


def comb(n, r):
    res = 1
    for i in range(r):
        res *= n - i
        res *= inv[i + 1]
        res %= mod
    return res


ans = total - comb(n, a) - comb(n, b)
if ans < 0:
    ans += mod
print(ans)

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

# 逆元配列の作成
inv = [1] * (2 * (10 ** 5)+1)
for i in range(2, 2 * (10 ** 5)+1):
    inv[i] = -inv[mod % i] * (mod // i)
    inv[i] %= mod


def comb(n, a):
    res = 1
    for i in range(a):
        res *= n - i  # 分子
        res *= inv[i + 1]  # 分母
        res %= mod  # modで割ったあまり
    return res


ans = pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)

ans %= mod
if ans < 0:
    ans += mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))
Min = min(p)
cnt = 0
for i in range(n):
    l = p[:i+1]
    p_i = p[i]
    if min(l) == p_i:
        cnt += 1
    if p_i == Min:
        break
print(cnt)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
cnt = 0
Min = p[0]
for i in range(n):
    if Min >= p[i]:
        cnt += 1
        Min = p[i]
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))
Min = min(p)
cnt = 0
for i in range(n):
    l = p[:i+1]
    if min(l) == p[i]:
        cnt += 1
        if p[i] == Min:
            break
print(cnt)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
cnt = 0
Min = p[0]
for i in range(n):
    if Min >= p[i]:
        cnt += 1
        Min = p[i]
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))
Min = min(p)
cnt = 0
for i in range(n):
    l = p[:i+1]
    if min(l) == p[i]:
        cnt += 1
        if p[i] == Min:
            break
print(cnt)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
cnt = 0
Min = p[0]
for i in range(n):
    if Min >= p[i]:
        cnt += 1
        Min = p[i]
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(n):
    l = p[:i+1]
    if min(l) == p[i]:
        cnt += 1
print(cnt)


Fixed submission:
n = int(input())
p = list(map(int, input().split()))
cnt = 0
Min = p[0]
for i in range(n):
    if Min >= p[i]:
        cnt += 1
        Min = p[i]
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
def factorial(n, p):
    ret = 1
    for i in range(n, 0, -1):
        ret *= i
        ret %= p
    return ret


def comb(n, r, p):
    r = min(r, n - r)
    a = factorial(r, p)
    b = factorial(n - r, p)
    ret = factorial(n, p) * pow(a, p - 2, p) * pow(b, p - 2, p) % p
    return ret


mod = 10 ** 9 + 7
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
ans = 0
sum_min = 0
for i in range(n - k + 1):
    cnt = comb(n - 1 - i, k - 1, mod)
    sum_min += a[i] * cnt
    sum_min %= mod

a_rev = a[::-1]
sum_max = 0
for i in range(n - k + 1):
    cnt = comb(n - 1 - i, k - 1, mod)
    sum_max += a_rev[i] * cnt
    sum_max %= mod
ans = (sum_max - sum_min) % mod
print(ans)


Fixed submission:
def cmb(n, r, p):
    if r < 0 or n < r:
        return 0
    r = min(r, n - r)
    return fact[n] * fact_inv[r] * fact_inv[n - r] % p


n, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
p = 10 ** 9 + 7
fact = [1, 1]  # fact[n] = (n! mod p)
fact_inv = [1, 1]  # fact_inv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # fact_invの計算用

for i in range(2, n + 1):
    fact.append(fact[-1] * i % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    fact_inv.append(fact_inv[-1] * inv[-1] % p)

i = 0
sum_max = 0
sum_min = 0
while n - i - 1 >= k - 1:
    cnt = cmb(n - i - 1, k - 1, p)
    sum_max += a[i] * cnt
    sum_min += a[n - i - 1] * cnt
    # print(i, a[i] * cnt, a[n - i - 1] * cnt)
    i += 1
ans = (sum_max - sum_min) % p
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
mod = 10 ** 9 + 7
for l in itertools.combinations(a, k):
    ans += l[-1] - l[0]
    ans %= mod
print(ans)

Fixed submission:
def cmb(n, r, p):
    if r < 0 or n < r:
        return 0
    r = min(r, n - r)
    return fact[n] * fact_inv[r] * fact_inv[n - r] % p


n, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
p = 10 ** 9 + 7
fact = [1, 1]  # fact[n] = (n! mod p)
fact_inv = [1, 1]  # fact_inv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # fact_invの計算用

for i in range(2, n + 1):
    fact.append(fact[-1] * i % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    fact_inv.append(fact_inv[-1] * inv[-1] % p)

i = 0
sum_max = 0
sum_min = 0
while n - i - 1 >= k - 1:
    cnt = cmb(n - i - 1, k - 1, p)
    sum_max += a[i] * cnt
    sum_min += a[n - i - 1] * cnt
    # print(i, a[i] * cnt, a[n - i - 1] * cnt)
    i += 1
ans = (sum_max - sum_min) % p
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())
print(a * b // math.gcd(a, b))

Fixed submission:
a, b = map(int, input().split())
# a, bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
# a, bの最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)

print(lcm(a, b))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
cnt = 1
idx = 0
if 1 in A:
    while idx > -1:
        if cnt in A:
            idx = A.index(cnt)
            A = A[idx:]
            cnt += 1
        else:
            idx = -1
    print(n - cnt + 1)
else:
    print(-1)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
cnt = 1
for i in A:
    if i == cnt:
        cnt += 1
if cnt == 1:
    print(-1)
else:
    print(n - cnt + 1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():    
    MOD = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    ans = 0
    for i in range(60):
        x = 0
        for j in range(n):
            if a[j] >> i & 1:
                x += 1
        ans += x * (n - x) * 2 ** i
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Fixed submission:
MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(60):
    x = 0
    for j in range(n):
        if a[j] >> i & 1:
            x += 1
    ans += x * (n - x) * 2 ** i
    ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(60):
    x = 0
    for j in range(n):
        if a[j] >> i & 1:
            x += 1
    ans += x * (n - x) * 2 ** i
    ans %= MOD
print(ans)

Fixed submission:
MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(60):
    x = 0
    for j in range(n):
        if a[j] >> i & 1:
            x += 1
    ans += x * (n - x) * 2 ** i
    ans %= MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
cost_1 = 0
cost_2 = 0
cost_3 = 0
cost_4 = 0
S = sum(A)
S_1 = sum(A)
S_2 = sum(A)
S_3 = sum(A)
S_4 = sum(A)
half = S / 2
l = 0
i = 0
while l < half:
    l += A[i]
    i += 1
l_big = l
l_small = l - A[i-1]
if l_big == S - l:
    print(0)
elif l_big - half < half - l_small:
    l_1 = l_big
    l_2 = l_big
    while l_1 > S_1 - l_big:
        l_1 -= 1
        cost_1 += 1
    while l_2 > S_2 - l_big:
        l_2 -= 1
        cost_2 += 1
    print(min(cost_1, cost_2))
else:
    l_3 = l_small
    l_4 = l_small
    while l_3 < S_3 - l_small:
        l_3 += 1
        cost_3 += 1
    while l_4 < S_4 - l_small:
        l_4 += 1
        cost_4 += 1
    print(min(cost_3, cost_4))

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
B = A[::-1]
S = [0] * n
S[0] = A[0]
T = [0] * n
T[0] = B[0]
ans = float('inf')
for i in range(1, n):
    S[i] = S[i - 1] + A[i]
    T[i] = T[i - 1] + B[i]
T = T[::-1]
ans = 2020202020 + 1
for i in range(n):
    diff = abs(S[i] - T[i] - A[i])
    ans = min(ans, diff)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
cost_1 = 0
cost_2 = 0
cost_3 = 0
cost_4 = 0
S = sum(A)
S_1 = sum(A)
S_2 = sum(A)
S_3 = sum(A)
S_4 = sum(A)
half = S / 2
l = 0
i = 0
while l < half:
    l += A[i]
    i += 1
l_big = l
l_small = l - A[i-1]
if l_big == S - l:
    print(0)
elif l_big - half < half - l_small:
    l_1 = l_big
    l_2 = l_big
    while l_1 > S_1 - l_big:
        l_1 -= 1
        cost_1 += 1
    while l_2 > S_2 - l_big:
        l_2 -= 1
        cost_2 += 1
    print(min(cost_1, cost_2))
else:
    l_3 = l_small
    l_4 = l_small
    while l_3 < S_3 - l_small:
        l_3 += 1
        cost_3 += 1
    while l_4 < S_4 - l_small:
        l_4 += 1
        cost_4 += 1
    print(min(cost_3, cost_4))

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
B = A[::-1]
S = [0] * n
S[0] = A[0]
T = [0] * n
T[0] = B[0]
ans = float('inf')
for i in range(1, n):
    S[i] = S[i - 1] + A[i]
    T[i] = T[i - 1] + B[i]
T = T[::-1]
ans = 2020202020 + 1
for i in range(n):
    diff = abs(S[i] - T[i] - A[i])
    ans = min(ans, diff)
print(ans)
Buggy python submission (verdict: Runtime Error):
mod = 10 ** 9 + 7
x, y = map(int, input().split())
if (x + y) % 3 != 0:
    print(0)
    exit()
a = 0
while y / x != 2 and x / y != 2:
    x -= 2
    y -= 1
    a += 1
b = min(x, y)

n = a + b
r = min(a, b)
x = 1
for i in range(n - r):
    x = x * (n - i) % mod
y = 1
for j in range(1, r):
    y = y * j
ans = x * pow(y, mod - 2, mod) % mod
print(ans)


Fixed submission:
mod = 10 ** 9 + 7
x, y = map(int, input().split())
a = (2 * y - x) // 3
b = (2 * x - y) // 3
if (x + y) % 3 != 0 or a < 0 or b < 0:
    print(0)
    exit()
n = a + b
r = min(a, b)
ans = 1
for i in range(r):
    ans = ans * (n - i) * pow(i + 1, mod - 2, mod) % mod
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_mat = np.array(A)
B_mat = np.array(B)
C_mat = B_mat - A_mat
C = C_mat.tolist()
x = 10 ** 10
num = 0
for i in range(len(C)):
    if 0 <= C[i] < x:
        x = C[i]
        num = i
if x == 10 ** 10:
    print('No')
else:
    A.pop(num)
    B.pop(num)

    A.sort()
    B.sort()

    A1_mat = np.array(A)
    B1_mat = np.array(B)

    C1_mat = B1_mat - A1_mat
    if np.all(C1_mat >= 0):
        print('Yes')
    else:
        print('No')

Fixed submission:
n = int(input())
if n % 2 == 1:
    ans = (n-1) // 2
else:
    ans = (n-2) // 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def main():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    ans = 0
    for i in range(n-2):
        a = l[i]  # 最小の辺の長さ
        for j in range(i + 1, n-1):
            b = l[j]  # 真ん中の辺の長さ
            ans += bisect_left(l[j+1:], a+b)
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
from bisect import bisect_left


n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0
for i in range(n-2):
    a = l[i]
    for j in range(i+1, n-1):
        b = l[j]
        cnt += bisect_left(l, a+b) - j - 1
        # bisec_left(l, x)でlの中にxを挿入できる点を探す
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations


def check(l):
    for i in range(3):
        a = l[i % 3]
        b = l[(i + 1) % 3]
        c = l[(i + 2) % 3]
        if a >= b + c:
            return False
    return True


n = int(input())
l = list(map(int , input().split()))
cnt = 0
for v in combinations(l, 3):
    if check(v):
        cnt += 1
print(cnt)

Fixed submission:
from bisect import bisect_left


n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0
for i in range(n-2):
    a = l[i]
    for j in range(i+1, n-1):
        b = l[j]
        cnt += bisect_left(l, a+b) - j - 1
        # bisec_left(l, x)でlの中にxを挿入できる点を探す
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))
l.sort()
count = 0
for i in range(len(l) - 2):
    a = l[i]
    for j in range(i + 1, len(l) - 1):
        b = l[j]
        r = a + b
        for k in range(j + 1, len(l)):
            c = l[k]
            if c < r:
                count += 1
            else:
                break
print(count)

Fixed submission:
from bisect import bisect_left


n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0
for i in range(n-2):
    a = l[i]
    for j in range(i+1, n-1):
        b = l[j]
        cnt += bisect_left(l, a+b) - j - 1
        # bisec_left(l, x)でlの中にxを挿入できる点を探す
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))
l.sort()
count = 0
for i in range(len(l) - 2):
    a = l[i]
    for j in range(i + 1, len(l) - 1):
        b = l[j]
        r = a + b
        for k in range(j + 1, len(l)):
            c = l[k]
            if c < r:
                count += 1
print(count)

Fixed submission:
from bisect import bisect_left


n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0
for i in range(n-2):
    a = l[i]
    for j in range(i+1, n-1):
        b = l[j]
        cnt += bisect_left(l, a+b) - j - 1
        # bisec_left(l, x)でlの中にxを挿入できる点を探す
print(cnt)
Buggy python submission (verdict: Runtime Error):
import math
s = list(input())
ss = s[:]
k = int(input())
cnt = 0

if len(set(s)) == 1:
    cnt = math.floor(len(s) * k / 2)
else:
    cnt = 0
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt += 1
            s[i + 1] = '*'
    cnt *= k
    if s[0] == s[-1]:
        a = 0
        for i in range(len(s) - 1):
            if ss[i] == ss[i + 1]:
                a += 1
        b = 0
        for j in range(len(s), 0, -1):
            if ss[j] == ss[j - 1]:
                b += 1
        cnt -= (k - 1) * (math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2))
print(cnt)

Fixed submission:
import math
s = list(input())
ss = s[:]
k = int(input())
cnt = 0

if len(set(s)) == 1:
    cnt = math.floor(len(s) * k / 2)
else:
    cnt = 0
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt += 1
            s[i + 1] = '*'
    cnt *= k
    if ss[0] == ss[-1]:
        a = 1
        for i in range(len(ss) - 1):
            if ss[i] == ss[i + 1]:
                a += 1
            else:
                break
        b = 1
        for j in range(len(ss) - 1, 0, -1):
            if ss[j] == ss[j - 1]:
                b += 1
            else:
                break
        cnt -= (k - 1) * (math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2))
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
sortedA = sorted(A)
B = [0 for i in range(n)]
for i in range(n):
    B[i] = A.index(sortedA[i])+1
print(*B)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
B = [0 for _ in range(n)]
for i, v in enumerate(A):
    B[v-1] = i+1
print(*B)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
ans = []
for i in range(1, n + 1):
    num = A.index(i) + 1
    ans.append(num)
print(*ans)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
B = [0 for _ in range(n)]
for i, v in enumerate(A):
    B[v-1] = i+1
print(*B)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
ans = []
for i in range(1, len(A) + 1):
    num = A.index(i) + 1
    ans.append(num)
print(*ans)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
B = [0 for _ in range(n)]
for i, v in enumerate(A):
    B[v-1] = i+1
print(*B)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
ans = []
for i in range(1, len(A) + 1):
    num = A.index(i) + 1
    ans.append(num)
print(*ans)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
B = [0 for _ in range(n)]
for i, v in enumerate(A):
    B[v-1] = i+1
print(*B)
Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
point = [k for _ in range(n)]
for i in range(q):
    point = list(map(lambda x: x-1, point))
    idx = int(input()) - 1
    point[idx] += 1
for j in range(n):
    if point[j] > 0:
        print('Yes')
    else:
        print('No')

Fixed submission:
n, k, q = map(int, input().split())
point = [k-q for _ in range(n)]
for i in range(q):
    idx = int(input()) - 1
    point[idx] += 1
for j in range(len(point)):
    if point[j] > 0:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
H = list(map(int, input().split()))
A = []


def f(x):
    cnt = 0
    while x < n-1:
        if H[x] >= H[x+1]:
            cnt += 1
            x += 1
        else:
            break
    return cnt


for i in range(n-1):
    A.append(f(i))
print(max(A))

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

tmp = 0
m = 0
for i in range(n-1):
    if H[i] >= H[i+1]:
        tmp += 1
    else:
        m = max(tmp, m)
        tmp = 0
print(max(m, tmp))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# import numpy as np

# 入力
N, Q = map(int, input().split())
g = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    g[a].append(b)
    g[b].append(a)
point = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    point[p] += x
ans = [0] * N
# 探索
def dfs(pre, now):
    # ansを更新
    ans[now] = ans[pre] + point[now]
    # 隣接頂点を探索
    for nxt in g[now]:
        if nxt == pre:
            continue
        dfs(now, nxt)
dfs(0, 0)
print(*ans)


Fixed submission:
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N, Q = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = [int(i) - 1 for i in input().split()]
        G[a].append(b)
        G[b].append(a)
    A = [0] * N  # 頂点数分だけ準備する
    for _ in range(Q):
        p, x = map(int, input().split())
        p -= 1
        A[p] += x
    que = deque([[-1, 0]])
    while que:
        par, vi = que.popleft()
        for vj in G[vi]:
            if vj == par:  # 探索が親の時はスルー
                continue
            A[vj] += A[vi]  # 数値を追加する
            que.append([vi, vj])  # queに(親，子)を追加する
    print(*A)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def main():
    n = int(input())
    l = []
    cnt = []
    for i in range(n):
        s = sorted(input())
        if not s in l:
            l.append(s)
            cnt.append(1)
        else:
            i = l.index(s)
            cnt[i] += 1
    ans = 0
    for i in cnt:
        ans += i*(i-1) // 2
    print(ans)


    print()
if __name__ == '__main__':
    main()


Fixed submission:
from collections import Counter

n = int(input())
S = []
for _ in range(n):
    s = sorted(list(input()))
    S.append(''.join(s))

S_cnt = Counter(S)

ans = 0
for k,v in S_cnt.items():
    ans += v*(v-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
cnt = 0
n = int(input())
S = []
for i in range(n):
    s = list(input())
    s.sort()
    S.append(s)
    cnt += S.count(S[i])-1
print(cnt)

Fixed submission:
from collections import Counter

n = int(input())
S = []
for _ in range(n):
    s = sorted(list(input()))
    S.append(''.join(s))

S_cnt = Counter(S)

ans = 0
for k,v in S_cnt.items():
    ans += v*(v-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools


n = int(input())
S = []
for i in range(n):
    s = list(input())
    s.sort()
    S.append(s)
cnt = 0
for v in itertools.combinations(S, 2):
    if v[0] == v[1]:
        cnt += 1
print(cnt)

Fixed submission:
from collections import Counter

n = int(input())
S = []
for _ in range(n):
    s = sorted(list(input()))
    S.append(''.join(s))

S_cnt = Counter(S)

ans = 0
for k,v in S_cnt.items():
    ans += v*(v-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [int(input()) for _ in range(n)]
for j in range(n):
    print(max(A[0:j] + A[j+1:]))

Fixed submission:
n = int(input())
A = [int(input()) for _ in range(n)]
max_id = A.index(max(A))
A = sorted(A, reverse=True)
for i in range(n):
    if i == max_id:
        # 最大値が取り除かれるので2番目に大きい数値を出力
        print(A[1])
    else:
        # 最大値が残っているので，最大値を出力
        print(A[0])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [0 for _ in range(n)]
for i in range(n):
    A[i] = int(input())
for j in range(n):
    print(max(A[0:j] + A[j+1:]))

Fixed submission:
n = int(input())
A = [int(input()) for _ in range(n)]
max_id = A.index(max(A))
A = sorted(A, reverse=True)
for i in range(n):
    if i == max_id:
        # 最大値が取り除かれるので2番目に大きい数値を出力
        print(A[1])
    else:
        # 最大値が残っているので，最大値を出力
        print(A[0])