Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
tmp=0
for i in range(n-1):
    for j in range(i+1,n):
        tmp += ((a[i] % mod) * (a[j] % mod)) % mod
print(tmp % mod)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
tmp = 0
sum = 0
for i in range(n):
    sum += a[i]
    sum %= mod
for i in range(n-1):
    sum -= a[i]
    if sum<0:
        sum+=mod
    tmp += a[i]*sum
    tmp %= mod 
print(tmp)

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

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
tmp = 0
sum = 0
for i in range(n):
    sum += a[i]
    sum %= mod
for i in range(n-1):
    sum -= a[i]
    if sum<0:
        sum+=mod
    tmp += a[i]*sum
    tmp %= mod 
print(tmp)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 0
#print('start')
while n!=0:
    ans += n%10
    n = int(n/10)
    #print(ans)
    #print(n)
if ans%9==0:
    print("Yes")
else:
    print("No")

Fixed submission:
n = input()
ans = 0
for i in range(len(n)):
    ans += int(n[i])
if(ans%9==0):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import math
s = int(input())
n = s//3
ans = 0
if n == 0:
    print(0)
else:
    for i in range(n):
        res = s-(3*(i+1))
        fact1 = math.factorial(res+i)
        fact2 = math.factorial(res)
        fact3 = math.factorial(i)
        ans += int(fact1/(fact2*fact3))
    print(ans % (10**9 + 7))

Fixed submission:
import math
s = int(input())
n = s//3
ans = 0
if n == 0:
    print(0)
else:
    for i in range(n):
        res = s-(3*(i+1))
        fact1 = math.factorial(res+i)
        if res == 0:
            fact2 = 1
        else:
            fact2 = math.factorial(res)
        if i == 0:
            fact3 = 1
        else:
            fact3 = math.factorial(i)
        ans += fact1//(fact2*fact3)
    print(ans % (10**9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
alist = list(map(int,input().split()))
wa = 0
answer = 0
for i in range(n):
    for j in range(n-i-1):
        wa += alist[i+j+1]
    wa = wa % (10**9 + 7)
    answer += wa * alist[i]
    answer = answer % (10**9 + 7)
    wa = 0
print(answer)

Fixed submission:
n = int(input())
alist = list(map(int,input().split()))
wa = sum(alist)
answer = 0
atai = wa
for i in range(n):
    atai -= alist[i]
    answer += atai * alist[i]
    answer = answer % (10**9 + 7)
print(answer)
Buggy python submission (verdict: Runtime Error):
x = int(input())
answer = 0
while x >= 10:
    answer += x%10
    x = int(x/10)
answer += x
if answer % 9 == 0:
    print('Yes')
else:
    print('No')

Fixed submission:
n = int(input())
nst = str(n)
keta= len(nst)
answer = 0
for i in range(keta):
    answer += int(nst[i])
if answer % 9 == 0:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
x = int(input())
answer = 0
while x >= 10:
    answer += x%10
    x = int(x/10)
answer += x
if answer % 9 == 0:
    print('Yes')
elif answer == 0:
    print('Yes')
else:
    print('No')

Fixed submission:
n = int(input())
nst = str(n)
keta= len(nst)
answer = 0
for i in range(keta):
    answer += int(nst[i])
if answer % 9 == 0:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
x = int(input())
import math
answer = 0
while x >= 10:
    answer += x%10
    x = math.floor(x/10)
answer += x
if answer % 9 == 0:
    print('Yes')
elif answer == 0:
    print('Yes')
else:
    print('No')

Fixed submission:
n = int(input())
nst = str(n)
keta= len(nst)
answer = 0
for i in range(keta):
    answer += int(nst[i])
if answer % 9 == 0:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
x = int(input())
answer = 0
while x >= 10:
    answer += x%10
    x = int(x/10)
answer += x
if answer % 9 == 0:
    print('Yes')
elif answer == 0:
    print('Yes')
else:
    print('No')

Fixed submission:
n = int(input())
nst = str(n)
keta= len(nst)
answer = 0
for i in range(keta):
    answer += int(nst[i])
if answer % 9 == 0:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
mod = 7 % k
if k % 2 == 0:
    print(-1)
else:
    ans = 1
    while mod != 0:
        mod = (10*mod + 7) % k
        ans += 1
        if ans >= 10**10:
            print(-1)
            break
    if ans < 10**10:
        print(ans)

Fixed submission:
k = int(input())
mod = 7 % k
if k % 2 == 0:
    print(-1)
else:
    ans = 1
    while mod != 0:
        mod = (10*mod + 7) % k
        ans += 1
        if ans >= 10**7:
            print(-1)
            break
    if ans < 10**7:
        print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
mod = 7 % k
if k % 2 == 0:
    print(-1)
else:
    ans = 1
    while mod != 0:
        mod = (10*mod + 7) % k
        ans += 1
    print(ans)

Fixed submission:
k = int(input())
mod = 7 % k
if k % 2 == 0:
    print(-1)
else:
    ans = 1
    while mod != 0:
        mod = (10*mod + 7) % k
        ans += 1
        if ans >= 10**7:
            print(-1)
            break
    if ans < 10**7:
        print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
score = int(input())
keta = 0
answer = 0
alpha = 7
if score % 2 == 0 or score % 10 == 5:
    print(-1)
elif score == 999983:
    print(999982)
else:
    while answer == 0:
        if alpha % score != 0:
            alpha = alpha*10 + 7
        else:
            answer = 1
        keta += 1
    print(keta)

Fixed submission:
k = int(input())
mod = 7 % k
if k % 2 == 0:
    print(-1)
else:
    ans = 1
    while mod != 0:
        mod = (10*mod + 7) % k
        ans += 1
        if ans >= 10**7:
            print(-1)
            break
    if ans < 10**7:
        print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
array = list(map(int,input().split()))
q = int(input())
sums = sum(array)
cnt = [0]*(10**5)
for i in array:
    cnt[i] += 1
for j in range(q):
    b,c = map(int,input().split())
    sums += cnt[b]*(c-b)
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(sums)

Fixed submission:
n = int(input())
array = list(map(int,input().split()))
q = int(input())
sums = sum(array)
cnt = [0]*(10**5+1)
for i in array:
    cnt[i] += 1
for j in range(q):
    b,c = map(int,input().split())
    sums += cnt[b]*(c-b)
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(sums)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
alist = list(map(int,input().split()))
q = int(input())
for i in range(q):
    b,c = map(int,input().split())
    alist = [c if s == b else s for s in alist]
    print(sum(alist))

Fixed submission:
n = int(input())
array = list(map(int,input().split()))
q = int(input())
sums = sum(array)
cnt = [0]*(10**5+1)
for i in array:
    cnt[i] += 1
for j in range(q):
    b,c = map(int,input().split())
    sums += cnt[b]*(c-b)
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(sums)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
alist = list(map(int,input().split()))
alist.sort()
ssum = sum(alist)
q = int(input())
for i in range(q):
    b,c = map(int,input().split())
    x = 0
    for j in range(n):
        if alist[j] == b:
            x = 1
            alist[j] = c
            ssum = ssum-b+c
        elif x == 1 and alist[j] != b:
            break
    print(ssum)

Fixed submission:
n = int(input())
array = list(map(int,input().split()))
q = int(input())
sums = sum(array)
cnt = [0]*(10**5+1)
for i in array:
    cnt[i] += 1
for j in range(q):
    b,c = map(int,input().split())
    sums += cnt[b]*(c-b)
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(sums)
Buggy python submission (verdict: Time Limit Exceeded):
kazu = int(input())
word = input()
score = word.split()
scin = [0]*kazu
zero = 0
for i in range(kazu):
    scin[i] = int(score[i])
    if scin[i] == 0:
        zero = 1

answer = 1
for j in range(kazu):
    answer *= scin[j]
    if answer > 10**18 and zero == 0:
        answer = -1

if zero == 1 and answer > 10**18:
    answer = -1

print(answer)

Fixed submission:
kazu = int(input())
word = input()
score = word.split()

maxn = 10**18
zero = 0
answer = 1
scin = [0]*kazu

for i in range(kazu):
    scin[i] = int(score[i])
    if scin[i] == 0:
        zero = 1
if zero == 1:
    answer = 0
else:
    for j in range(kazu):
        answer *= scin[j]
        if answer > maxn:
            answer = -1
            break
print(answer)

Buggy python submission (verdict: Runtime Error):
kazu = int(input())
word = input()
score = word.split()
scin = [0]*kazu
zero = 0
for i in range(kazu):
    scin[i] = int(score[i])
    if scin[i] == 0:
        zero = 1:

answer = 1
for j in range(kazu):
    answer *= scin[j]
    if answer > 10**18 and zero == 0:
        answer = -1

if zero == 1 and answer > 10**18:
    answer = -1

print(answer)

Fixed submission:
kazu = int(input())
word = input()
score = word.split()

maxn = 10**18
zero = 0
answer = 1
scin = [0]*kazu

for i in range(kazu):
    scin[i] = int(score[i])
    if scin[i] == 0:
        zero = 1
if zero == 1:
    answer = 0
else:
    for j in range(kazu):
        answer *= scin[j]
        if answer > maxn:
            answer = -1
            break
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
kazu = int(input())
word = input()
score = word.split()
scin = [0]*kazu
for i in range(kazu):
    scin[i] = int(score[i])

answer = 1
for j in range(kazu):
    answer *= scin[j]
    
if answer > 10**18:
    answer = -1

print(answer)

Fixed submission:
kazu = int(input())
word = input()
score = word.split()

maxn = 10**18
zero = 0
answer = 1
scin = [0]*kazu

for i in range(kazu):
    scin[i] = int(score[i])
    if scin[i] == 0:
        zero = 1
if zero == 1:
    answer = 0
else:
    for j in range(kazu):
        answer *= scin[j]
        if answer > maxn:
            answer = -1
            break
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import math
a,b,n = map(int,input().split())
maxx = n//b
ans = 0
for i in range(min(maxx,10**8)):
    x = b*(maxx-i)-1
    ans = max(math.floor(a*x/b)-a*(math.floor(x/b)),ans)
ans = max(math.floor(a*n/b)-a*(math.floor(n/b)),ans)
print(ans)

Fixed submission:
a,b,n=map(int,input().split())
x=min(b-1,n) #上記よりxとしてmin(B-1,N)を選ぶのが最善
print((a*x)//b-a*(x//b))

Buggy python submission (verdict: Time Limit Exceeded):
import math
a,b,n = map(int,input().split())
maxx = n//b
ans = 0
for i in range(min(maxx,10**9)):
    x = b*(maxx-i)-1
    ans = max(math.floor(a*x/b)-a*(math.floor(x/b)),ans)
ans = max(math.floor(a*n/b)-a*(math.floor(n/b)),ans)
print(ans)

Fixed submission:
a,b,n=map(int,input().split())
x=min(b-1,n) #上記よりxとしてmin(B-1,N)を選ぶのが最善
print((a*x)//b-a*(x//b))

Buggy python submission (verdict: Time Limit Exceeded):
import math
a,b,n = map(int,input().split())
maxx = n//b
ans = 0
for i in range(maxx):
    x = b*(i+1)-1
    ans = max(math.floor(a*x/b)-a*(math.floor(x/b)),ans)
ans = max(math.floor(a*n/b)-a*(math.floor(n/b)),ans)
print(ans)

Fixed submission:
a,b,n=map(int,input().split())
x=min(b-1,n) #上記よりxとしてmin(B-1,N)を選ぶのが最善
print((a*x)//b-a*(x//b))
Buggy python submission (verdict: Runtime Error):
scnum = int(input())
score = []
answer = 0
for i in range(scnum):
    word = input()
    if word in score:
        answer += 0
    else:
        score.append(word)
        answer += 1

print(answer)

Fixed submission:
score = list(map(int,input().split()))
if score[0] <= score[1]:
    print('unsafe')
else:
    print('safe')
Buggy python submission (verdict: Time Limit Exceeded):
scnum = int(input())
score = []
answer = 0
for i in range(scnum):
    word = input()
    if word not in score:
        score.append(word)
        answer += 1

print(answer)

Fixed submission:
scnum = int(input())
word = [0]*scnum
for i in range(scnum):
    word[i] = input()
word.sort()
answer = 1

for j in range(scnum-1):
    if word[j] != word[j+1]:
        answer += 1
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
scnum = int(input())
score = ['0']*scnum
answer = 0
for i in range(scnum):
    word = input()
    if word not in score:
        score[i] = word
        answer += 1

print(answer)

Fixed submission:
scnum = int(input())
word = [0]*scnum
for i in range(scnum):
    word[i] = input()
word.sort()
answer = 1

for j in range(scnum-1):
    if word[j] != word[j+1]:
        answer += 1
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
number = int(input())
score = list(map(int,input().split()))
cancel = 0
for i in range(number):
    if score.count(score[i]) != 1:
        cancel = 1
        break
if cancel == 1:
    print('NO')
else:
    print('YES')

Fixed submission:
number = int(input())
score = list(map(int,input().split()))
score.sort()
cancel = 0
for i in range(number-1):
    if score[i] == score[i+1]:
        cancel = 1
        break
if cancel == 1:
    print('NO')
else:
    print('YES')
Buggy python submission (verdict: Runtime Error):
number = list(map(int,input().split()))
score = list(map(int,input().split()))
score.sort()
answer = 0
for i in range(number[1]):
    score[number[0]-1-i] = 0
for j in range(number[0]):
    answer += score[j]
print(answer)

Fixed submission:
number = list(map(int,input().split()))
score = list(map(int,input().split()))
score.sort()
answer = 0
if number[1] > number [0]:
    number[1] = number[0]
for i in range(number[1]):
    score[number[0]-1-i] = 0
for j in range(number[0]):
    answer += score[j]
print(answer)
Buggy python submission (verdict: Runtime Error):
    from collections import deque

    H, W = map(int, input().split())
    ch, cw = map(lambda x: int(x)-1, input().split())
    dh, dw = map(lambda x: int(x)-1, input().split())
    S = [list(input()) for _ in range(H)]
    dist = [[-1] * W for _ in range(H)]

    q = deque()
    q.append((0, ch, cw))
    while q:
        c, h, w = q.popleft()
        if dist[h][w] >= 0:
            continue
        dist[h][w] = c
        for hh in range(-2, 3):
            for ww in range(-2, 3):
                if 0 <= h+hh < H and 0 <= w+ww < W and S[h+hh][w+ww] == "." and dist[h+hh][w+ww] < 0:
                    if (hh, ww) in ((0,1), (1,0), (-1,0), (0,-1)):
                        q.appendleft((c, h+hh, w+ww)) # 徒歩は前に追加
                    else:
                        q.append((c+1, h+hh, w+ww)) # ワープは後ろに追加

    print(dist[dh][dw])

Fixed submission:
from collections import deque

H, W = map(int, input().split())
ch, cw = map(lambda x: int(x)-1, input().split())
dh, dw = map(lambda x: int(x)-1, input().split())
S = [list(input()) for _ in range(H)]
dist = [[-1] * W for _ in range(H)]

q = deque()
q.append((0, ch, cw))
while q:
    c, h, w = q.popleft()
    if dist[h][w] >= 0:
        continue
    dist[h][w] = c
    for hh in range(-2, 3):
        for ww in range(-2, 3):
            if 0 <= h+hh < H and 0 <= w+ww < W and S[h+hh][w+ww] == "." and dist[h+hh][w+ww] < 0:
                if (hh, ww) in ((0,1), (1,0), (-1,0), (0,-1)):
                    q.appendleft((c, h+hh, w+ww)) # 徒歩は前に追加
                else:
                    q.append((c+1, h+hh, w+ww)) # ワープは後ろに追加

print(dist[dh][dw])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
H, W, M = map(int, input().split())
rows = {i: 0 for i in range(H)}
cols = {i: 0 for i in range(W)}
d = defaultdict(int)
for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    rows[h] += 1
    cols[w] += 1
    d[(h,w)] += 1
max_rows = [kv for kv in rows.items() if kv[1] == max(rows.values())]
max_cols = [kv for kv in cols.items() if kv[1] == max(cols.values())]
non_dup = False
ans = max_rows[0][1] + max_cols[0][1]
flg = False
for kh, vh in max_rows:
    for kw, vw in max_cols:
        if d[(kh, kw)] == 0:
            non_dup = True
            flg = True
            break
    if flg:
        break
if not non_dup:
    ans -= 1
print(ans)

Fixed submission:
from collections import defaultdict
H, W, M = map(int, input().split())
rows = {i: 0 for i in range(H)}
cols = {i: 0 for i in range(W)}
d = defaultdict(int)
for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    rows[h] += 1
    cols[w] += 1
    d[(h,w)] += 1
mr = max(rows.values())
mc = max(cols.values())
max_rows = [kv for kv in rows.items() if kv[1] == mr]
max_cols = [kv for kv in cols.items() if kv[1] == mc]
non_dup = False
ans = max_rows[0][1] + max_cols[0][1]
flg = False
for kh, vh in max_rows:
    for kw, vw in max_cols:
        if d[(kh, kw)] == 0:
            non_dup = True
            flg = True
            break
    if flg:
        break
if not non_dup:
    ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
H, W, M = map(int, input().split())
rows = {i: 0 for i in range(H)}
cols = {i: 0 for i in range(W)}
d = defaultdict(int)
for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    rows[h] += 1
    cols[w] += 1
    d[(h,w)] += 1
max_rows = [kv for kv in rows.items() if kv[1] == max(rows.values())]
max_cols = [kv for kv in cols.items() if kv[1] == max(cols.values())]
non_dup = False
ans = max_rows[0][1] + max_cols[0][1]
for kh, vh in max_rows:
    for kw, vw in max_cols:
        if d[(kh, kw)] == 0:
            non_dup = True
            break
if not non_dup:
    ans -= 1
print(ans)

Fixed submission:
from collections import defaultdict
H, W, M = map(int, input().split())
rows = {i: 0 for i in range(H)}
cols = {i: 0 for i in range(W)}
d = defaultdict(int)
for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    rows[h] += 1
    cols[w] += 1
    d[(h,w)] += 1
mr = max(rows.values())
mc = max(cols.values())
max_rows = [kv for kv in rows.items() if kv[1] == mr]
max_cols = [kv for kv in cols.items() if kv[1] == mc]
non_dup = False
ans = max_rows[0][1] + max_cols[0][1]
flg = False
for kh, vh in max_rows:
    for kw, vw in max_cols:
        if d[(kh, kw)] == 0:
            non_dup = True
            flg = True
            break
    if flg:
        break
if not non_dup:
    ans -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import sqrt
N = int(input())
ans = [0] * (N+1)
x = int(sqrt(N-2))+1
for j in range(1, x):
    for k in range(1, x):
        for l in range(1, x):
            y = j**2+k**2+l**2+j*k+k*l+l*j
            if y <= N:
                ans[y] += 1
for n in ans[1:N+1]:
    print(n)

Fixed submission:
from math import sqrt
N = int(input())
if N == 1:
    print(0)
    import sys
    sys.exit()
ans = [0] * (N+1)
x = int(sqrt(N-2))+1
for j in range(1, x):
    for k in range(1, x):
        for l in range(1, x):
            y = j**2+k**2+l**2+j*k+k*l+l*j
            if y <= N:
                ans[y] += 1
for n in ans[1:N+1]:
    print(n)

Buggy python submission (verdict: Time Limit Exceeded):
from math import sqrt

N = int(input())
for i in range(1, N+1):
    ans = 0
    if i <= 5:
        print(0)
        continue
    x = int(sqrt(i-2))+1
    for j in range(1, x):
        for k in range(1, x):
            for l in range(1, x):
                if j**2+k**2+l**2+j*k+k*l+l*j==i:
                    ans += 1
                    break
                elif j**2+k**2+l**2+j*k+k*l+l*j>i:
                    break
    print(ans)

Fixed submission:
from math import sqrt
N = int(input())
if N == 1:
    print(0)
    import sys
    sys.exit()
ans = [0] * (N+1)
x = int(sqrt(N-2))+1
for j in range(1, x):
    for k in range(1, x):
        for l in range(1, x):
            y = j**2+k**2+l**2+j*k+k*l+l*j
            if y <= N:
                ans[y] += 1
for n in ans[1:N+1]:
    print(n)

Buggy python submission (verdict: Time Limit Exceeded):
from math import sqrt

N = int(input())
for i in range(1, N+1):
    ans = 0
    if i <= 5:
        print(0)
        continue
    for j in range(1, int(sqrt(i-2))+1):
        for k in range(1, int(sqrt(i-2))+1):
            for l in range(1, int(sqrt(i-2))+1):
                if j**2+k**2+l**2+j*k+k*l+l*j==i:
                    ans += 1
    print(ans)

Fixed submission:
from math import sqrt
N = int(input())
if N == 1:
    print(0)
    import sys
    sys.exit()
ans = [0] * (N+1)
x = int(sqrt(N-2))+1
for j in range(1, x):
    for k in range(1, x):
        for l in range(1, x):
            y = j**2+k**2+l**2+j*k+k*l+l*j
            if y <= N:
                ans[y] += 1
for n in ans[1:N+1]:
    print(n)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
mod = 10**9 + 7
plus = []
minus = []
zlen = 0
for i in map(int, input().split()):
    if i >= 0:
        plus.append(i)
    elif i < 0:
        minus.append(i)
    else:
        zlen += 1
plen = len(plus)
mlen = len(minus)
if K > plen + mlen:
    print(0)
    import sys
    sys.exit()
plus.sort(reverse=True)
minus.sort()
pp = [1]
mp = [1]
for p in plus:
    pp.append((pp[-1]*p))
for m in minus:
    mp.append((mp[-1]*(-m)))
ppm = [1]
mpm = [1]
for p in plus[::-1]:
    ppm.append((ppm[-1]*p))
for m in minus[::-1]:
    mpm.append((mpm[-1]*(-m)))
ans = -float("inf")
ans_m = float("inf")
# kこマイナスから選ぶ
for k in range(K+1):
    if mlen < k:
        continue
    if plen < K-k:
        continue
    # 最大を目指す
    if k % 2 == 0:
        tmp = mp[k] * pp[K-k]
        ans = max(ans, tmp)
    # 絶対値最小を目指す
    else:
        tmp = mpm[k] * ppm[K-k]
        ans = min(ans, tmp)
if ans == -float("inf"):
    ans = -ans_m
if ans < 0 and zlen > 0:
    print(0)
    import sys
    sys.exit()
print(ans%mod)

Fixed submission:
N = int(input())
ans = 0
for i in range(1, N+1):
    ans += i * (N-i+1)
for _ in range(N-1):
    u, v = map(int, input().split())
    if u > v:
        u, v = v, u
    ans -= u * (N-v+1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
dp = [1] * (N+1)
for i in range(2, N+1):
    k = 1
    while i * k <= N:
        dp[i*k] += 1
        k += 1
ans = 0
for i in range(1, N+1):
    ans += i * dp[i]
print(ans)


Fixed submission:
N = int(input())
dp = [1] * (N+1)
for i in range(2, N+1):
    k = 1
    while i * k <= N:
        dp[i*k] += 1
        k += 1
ans = 0
for i in range(1, N+1):
    ans += i * dp[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
mod = 10**9 + 7

def comb(n, r, mod):
    if r<0 or r>n:
        return 0
    r = min(r, n-r)
    return fac[n] * (finv[r] * finv[n-r] % mod) % mod

def perm(n, r, mod):
    if r<0 or r>n:
        return 0
    return (fac[n] * finv[n-r]) % mod

fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, max(N + 1, M + 1)):
    fac.append((fac[-1] * i) % mod)
    inv.append((-inv[mod%i] * (mod//i)) % mod)
    finv.append((finv[-1] * inv[-1]) % mod)
for i in range(N+1):
    ans += (-1)**i * ((comb(N, i, mod) * perm(M, i, mod))%mod * (perm(M-i, N-i, mod)**2)%mod)%mod
    ans %= mod
print(ans)

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

def comb(n, r, mod):
    if r<0 or r>n:
        return 0
    r = min(r, n-r)
    return fac[n] * (finv[r] * finv[n-r] % mod) % mod

def perm(n, r, mod):
    if r<0 or r>n:
        return 0
    return (fac[n] * finv[n-r]) % mod

fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, max(N + 1, M + 1)):
    fac.append((fac[-1] * i) % mod)
    inv.append((-inv[mod%i] * (mod//i)) % mod)
    finv.append((finv[-1] * inv[-1]) % mod)
c = comb(M, N, mod)
ans = ((fac[N] * c % mod) ** 2) % mod

for i in range(1, N+1):
    ans += (-1)**i * ((comb(N, i, mod) * perm(M, i, mod))%mod * (perm(M-i, N-i, mod)**2)%mod)%mod
    ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
a = input()
if a.isupper():
  print("A)
else:
  print("a")

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    a = input().rstrip()
    if a.isupper():
        print("A")
    else:
        print("a")

if __name__ == '__main__':
    main()