Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 6)

def main():
    def dfs(i,oi=-1,s=0):
        ans[i]=s+d[i]
        for ki in to[i]:
            if ki==oi:continue
            dfs(ki,i,s+d[i])

    n,q=map(int, input().split())
    to=defaultdict(list)
    d=[0]*n
    ans=[0]*n
    for _ in range(n-1):
        a,b=map(int, input().split())
        a-=1
        b-=1
        to[a].append(b)
        to[b].append(a)
    for _ in range(q):
        p, x = map(int, input().split())
        d[p-1]+=x
    dfs(0)
    print(*ans)

main()

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 6)
input=sys.stdin.readline

def main():
    def dfs(i,oi=-1,s=0):
        ans[i]=s+d[i]
        for ki in to[i]:
            if ki==oi:continue
            dfs(ki,i,s+d[i])

    n,q=map(int, input().split())
    to=defaultdict(list)
    d=[0]*n
    ans=[0]*n
    for _ in range(n-1):
        a,b=map(int, input().split())
        a-=1
        b-=1
        to[a].append(b)
        to[b].append(a)
    for _ in range(q):
        p, x = map(int, input().split())
        d[p-1]+=x
    dfs(0)
    print(*ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 6)

def main():
    def dfs(i,oi=-1,s=0):
        ans[i]=s+d[i]
        for ki in to[i]:
            if ki==oi:continue
            dfs(ki,i,s+d[i])

    n,q=map(int, input().split())
    to=defaultdict(list)
    d=[0]*n
    ans=[0]*n
    for _ in range(n-1):
        a,b=map(int, input().split())
        a-=1
        b-=1
        to[a].append(b)
        to[b].append(a)
    for _ in range(q):
        p, x = map(int, input().split())
        d[p-1]+=x
    dfs(0)
    print(*ans)

main()

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 6)
input=sys.stdin.readline

def main():
    def dfs(i,oi=-1,s=0):
        ans[i]=s+d[i]
        for ki in to[i]:
            if ki==oi:continue
            dfs(ki,i,s+d[i])

    n,q=map(int, input().split())
    to=defaultdict(list)
    d=[0]*n
    ans=[0]*n
    for _ in range(n-1):
        a,b=map(int, input().split())
        a-=1
        b-=1
        to[a].append(b)
        to[b].append(a)
    for _ in range(q):
        p, x = map(int, input().split())
        d[p-1]+=x
    dfs(0)
    print(*ans)

main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

n=int(input())
ss=[input() for _ in range(n)]
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        if Counter(ss[i])==Counter(ss[j]):
            ans+=1
print(ans)

Fixed submission:
from collections import defaultdict

n = int(input())
cnt = defaultdict(int)
for _ in range(n):
    s = list(input())
    s.sort()
    s = tuple(s)
    cnt[s] += 1
print(sum(v * (v - 1) // 2 for v in cnt.values() if v > 1))
Buggy python submission (verdict: Runtime Error):
def yakusu(n):
    m=1
    re=[]
    while m**2<n:
        a,md=divmod(n,m)
        if md==0:
            re.append(m)
            re.append(a)
        m+=1
    if m**2==n:
        re.append(m)
    return re

n, k = map(int, input().split())
aa = list(map(int, input().split()))
yk = yakusu(sum(aa))
yk.sort(reverse=True)
for y in yk:
    rs=[a%y for a in aa if a%y]
    rs.sort()
    l=0
    sl=rs[0]
    r=len(rs)-1
    sr=y-rs[r]
    while 1:
        if l+1==r:
            if sl==sr and sl<=k:
                print(y)
                exit()
            else:
                break
        if sl>sr:
            r-=1
            sr+=y-rs[r]
            if sr>k:break
        else:
            l+=1
            sl+=rs[l]
            if sl>k:break
print(1)


Fixed submission:
def yakusu(n):
    m = 1
    re = []
    while m ** 2 < n:
        a, md = divmod(n, m)
        if md == 0:
            re.append(m)
            re.append(a)
        m += 1
    if m ** 2 == n:
        re.append(m)
    return re

n, k = map(int, input().split())
aa = list(map(int, input().split()))
yk = yakusu(sum(aa))
yk.sort(reverse=True)
for y in yk:
    rs = [a % y for a in aa if a % y]
    if not rs:
        print(y)
        exit()
    if len(rs)==1:continue
    rs.sort()
    l = 0
    sl = rs[0]
    r = len(rs) - 1
    sr = y - rs[r]
    while 1:
        if l + 1 == r:
            if sl == sr and sl <= k:
                print(y)
                exit()
            else:
                break
        if sl > sr:
            r -= 1
            sr += y - rs[r]
            if sr > k: break
        else:
            l += 1
            sl += rs[l]
            if sl > k: break
print(1)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
md = 10 ** 9 + 7
if k % 2:
    print(0)
    exit()
k //= 2
dp = [[[0] * (n ** 2) for _ in range(n + 2)] for __ in range(n + 1)]
dp[0][0][0] = 1
for i in range(1, n + 1):
    dpi1 = dp[i - 1]
    for j in range(i + 1):
        for s in range(j, k + 1):
            # 片側、水平、両方上
#            print(i,j,s)
            tmp = dpi1[j][s - j] * j * 2 + dpi1[j][s - j] + dpi1[j + 1][s - j] * (j + 1) ** 2
            if j:
                # 両方保留
                tmp += dp[i - 1][j - 1][s - j]
            dp[i][j][s] = tmp % md
print(dp[n][0][k])


Fixed submission:
def f(n,k):
    md = 10 ** 9 + 7
    if k % 2:
        print(0)
        exit()
    k //= 2
    dp = [[[0] * (n ** 2) for _ in range(n + 2)] for __ in range(n + 1)]
    dp[0][0][0] = 1
    for i in range(1, n + 1):
        dpi1 = dp[i - 1]
        for j in range(i + 1):
            for s in range(j, k + 1):
                # 片側、水平、両方上
                #            print(i,j,s)
                tmp = dpi1[j][s - j] * j * 2 + dpi1[j][s - j] + dpi1[j + 1][s - j] * (j + 1) ** 2
                if j:
                    # 両方保留
                    tmp += dp[i - 1][j - 1][s - j]
                dp[i][j][s] = tmp % md
    print(dp[n][0][k])

n, k = map(int, input().split())
f(n,k)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
md = 10 ** 9 + 7
if k % 2:
    print(0)
    exit()
k //= 2
dp = [[[0] * (n ** 2) for _ in range(n + 1)] for __ in range(n + 1)]
dp[0][0][0] = 1
for i in range(1, n + 1):
    dpi1 = dp[i - 1]
    for j in range(i + 1):
        for s in range(j, k + 1):
            # 片側、水平、両方上
            tmp = dpi1[j][s - j] * j * 2 + dpi1[j][s - j] + dpi1[j + 1][s - j] * (j + 1) ** 2
            if j:
                # 両方保留
                tmp += dp[i - 1][j - 1][s - j]
            dp[i][j][s] = tmp % md
print(dp[n][0][k])


Fixed submission:
def f(n,k):
    md = 10 ** 9 + 7
    if k % 2:
        print(0)
        exit()
    k //= 2
    dp = [[[0] * (n ** 2) for _ in range(n + 2)] for __ in range(n + 1)]
    dp[0][0][0] = 1
    for i in range(1, n + 1):
        dpi1 = dp[i - 1]
        for j in range(i + 1):
            for s in range(j, k + 1):
                # 片側、水平、両方上
                #            print(i,j,s)
                tmp = dpi1[j][s - j] * j * 2 + dpi1[j][s - j] + dpi1[j + 1][s - j] * (j + 1) ** 2
                if j:
                    # 両方保留
                    tmp += dp[i - 1][j - 1][s - j]
                dp[i][j][s] = tmp % md
    print(dp[n][0][k])

n, k = map(int, input().split())
f(n,k)
Buggy python submission (verdict: Runtime Error):
import numpy as np
n=int(input())
a=list(map(int,input().split()))
a=[[x] for x in a]
a=np.array(a)
k=np.zeros((n,n),dtype="i8")
for i in range(n-1):
    k[i][i]=1
    k[i][i+1]=1
k[n-1][0]=1
k[n-1][-1]=1
k=np.linalg.inv(k)
ka=np.dot(k,a)
ans=[]
for x in ka:
    ans.append(int(x[0])*2)
print(*ans)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a0=sum(a)//2-sum(a[1::2])
ans=[a0*2]
for i in range(n-2):
    ans.append(a[i]*2-ans[-1])
ans.append((a[-1]-a0)*2)
print(*ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

def com(m,r):
    if r>m/2:
        r=m-r
    if r==0:
        return 1
    t=(m,r)
    if t in memo:
        return memo[t]
    memo[t]=re=com(m,r-1)*(m-r+1)//r
    return re

n,k=map(int,input().split())
memo={}
md=10**9+7
for i in range(1,k+1):
    ans=com(n-k+1,i)*com(k-1,i-1)%md
    print(ans)

Fixed submission:
n,k=map(int,input().split())
md=10**9+7
n1=n-k+1
n2=k-1
com1=[]
com2=[]
c1=1
c2=1
for i in range(k+1):
    com1+=[c1]
    com2+=[c2]
    c1=c1*(n1-i)//(i+1)
    c2 = c2 * (n2 - i) // (i + 1)
for i in range(1,k+1):
    ans=com1[i]*com2[i-1]%md
    print(ans)

Buggy python submission (verdict: Runtime Error):
def com(m,r):
    if r>m/2:
        r=m-r
    if r==0:
        return 1
    t=(m,r)
    if t in memo:
        return memo[t]
    memo[t]=re=com(m,r-1)*(m-r+1)//r
    return re

n,k=map(int,input().split())
memo={}
md=10**9+7
for i in range(1,k+1):
    ans=com(n-k+1,i)*com(k-1,i-1)%md
    print(ans)

Fixed submission:
n,k=map(int,input().split())
md=10**9+7
n1=n-k+1
n2=k-1
com1=[]
com2=[]
c1=1
c2=1
for i in range(k+1):
    com1+=[c1]
    com2+=[c2]
    c1=c1*(n1-i)//(i+1)
    c2 = c2 * (n2 - i) // (i + 1)
for i in range(1,k+1):
    ans=com1[i]*com2[i-1]%md
    print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
md=10**9+7
a=[0]*n
for i in range(1,n+1):
    a[i-1]=n//i
#print(a)
ans=a[:]
for _ in range(k-2):
    ans=[sum(ans[:ak])%md for ak in a]
#    print(ans)
print(sum(ans)%md)

Fixed submission:
def f(n,k):
    lim = int((n + 0.1) ** 0.5) + 1
    ws = []
    s = 0
    for i in range(1, lim):
        w = n // i - n // (i + 1)
        ws.append(w)
        s += w
    ws += [1] * (n - s)
    m = len(ws)
    dp0 = ws[::-1]
    dp1 = [0] * m
    for _ in range(k - 1):
        s = 0
        for j in range(m):
            s += dp0[j]
            dp1[m - j - 1] = (s * ws[j]) % md
        dp0 = dp1[:]
    print(sum(dp0) % md)
md=10**9+7
n,k=map(int,input().split())
f(n,k)
Buggy python submission (verdict: Runtime Error):
from math import gcd

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

def kosu(b, c, d):
    return b - ((b // c) + (b // d) - (b // lcm(c, d)))

a, b, c, d = map(int, input().split())
print(kosu(b, c, d) - kosu(a - 1, c, d))


Fixed submission:
def gcd(x,y):
    while y:
        x,y=y,x%y
    return x

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

def kosu(b, c, d):
    return b - ((b // c) + (b // d) - (b // lcm(c, d)))

a, b, c, d = map(int, input().split())
print(kosu(b, c, d) - kosu(a - 1, c, d))
Buggy python submission (verdict: Runtime Error):
def dfs(x, al):
    global cntx, cnty
    if (al, x) in used:
        return
    used.add((al, x))
    if al == 0:
        cntx += 1
    else:
        cnty += 1
    for xy in to[al][x]:
        dfs(xy, 1 - al)
    return

n = int(input())
to = [{}, {}]
for _ in range(n):
    x, y = map(int, input().split())
    to[0].setdefault(x, [])
    to[1].setdefault(y, [])
    to[0][x] += [y]
    to[1][y] += [x]
used = set()
ans = 0
for x in to[0].keys():
    if (0, x) in used: continue
    cntx = 0
    cnty = 0
    dfs(x, 0)
    ans += cntx * cnty
print(ans - n)


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

def dfs(x, al):
    global cntx, cnty
    if (al, x) in used:
        return
    used.add((al, x))
    if al == 0:
        cntx += 1
    else:
        cnty += 1
    for xy in to[al][x]:
        dfs(xy, 1 - al)
    return

n = int(input())
to = [{}, {}]
for _ in range(n):
    x, y = map(int, input().split())
    to[0].setdefault(x, [])
    to[1].setdefault(y, [])
    to[0][x] += [y]
    to[1][y] += [x]
used = set()
ans = 0
for x in to[0].keys():
    if (0, x) in used: continue
    cntx = 0
    cnty = 0
    dfs(x, 0)
    ans += cntx * cnty
print(ans - n)
Buggy python submission (verdict: Time Limit Exceeded):
md=10**9+7
n,m=map(int,input().split())
s=list(input().split())
t=list(input().split())
dp=[[1]*(m+1) for _ in range(n+1)]
for i,sk in enumerate(s):
    dp[i+1]=dp[i][:]
    cs=0
    for j,tk in enumerate(t):
        if sk==tk:
            cs+=dp[i][j]
        dp[i+1][j+1]+=cs
print(dp[-1][-1]%md)

Fixed submission:
def f(n, m):
    s = list(input().split())
    t = list(input().split())
    dp = [[1] * (m + 1) for _ in range(n + 1)]
    for i, sk in enumerate(s):
        dpi1 = dp[i + 1] = dp[i][:]
        cs = 0
        for j, tk in enumerate(t):
            if sk == tk:
                cs = (cs + dp[i][j]) % md
            dpi1[j + 1] = (dpi1[j + 1] + cs) % md
#    for x in dp:
#        print(*x)
    print(dp[-1][-1])

md = 10 ** 9 + 7
n, m = map(int, input().split())
f(n, m)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

md=10**9+7
n,m=map(int,input().split())
s=list(input().split())
t=list(input().split())
dp=np.zeros((n+1,m+1),dtype="i8")
dp[0][0]=1
for i,sk in enumerate(s):
    for j,tk in enumerate(t):
        if sk==tk:
            dp[i+1][j+1]=np.sum(dp[:i+1,:j+1])%md
print(np.sum(dp)%md)

Fixed submission:
def f(n, m):
    s = list(input().split())
    t = list(input().split())
    dp = [[1] * (m + 1) for _ in range(n + 1)]
    for i, sk in enumerate(s):
        dpi1 = dp[i + 1] = dp[i][:]
        cs = 0
        for j, tk in enumerate(t):
            if sk == tk:
                cs = (cs + dp[i][j]) % md
            dpi1[j + 1] = (dpi1[j + 1] + cs) % md
#    for x in dp:
#        print(*x)
    print(dp[-1][-1])

md = 10 ** 9 + 7
n, m = map(int, input().split())
f(n, m)

Buggy python submission (verdict: Time Limit Exceeded):
md=10**9+7
n,m=map(int,input().split())
s=list(input().split())
t=list(input().split())
dp=[[0]*(m+3) for _ in range(n+3)]
dp[0][0]=1
for i,sk in enumerate(s):
    for j,tk in enumerate(t):
        if sk==tk:
            dp[i+1][j+1]=sum(sum(dpi[:j+1]) for dpi in dp[:i+1])
print(sum(sum(dpi) for dpi in dp)%md)

Fixed submission:
def f(n, m):
    s = list(input().split())
    t = list(input().split())
    dp = [[1] * (m + 1) for _ in range(n + 1)]
    for i, sk in enumerate(s):
        dpi1 = dp[i + 1] = dp[i][:]
        cs = 0
        for j, tk in enumerate(t):
            if sk == tk:
                cs = (cs + dp[i][j]) % md
            dpi1[j + 1] = (dpi1[j + 1] + cs) % md
#    for x in dp:
#        print(*x)
    print(dp[-1][-1])

md = 10 ** 9 + 7
n, m = map(int, input().split())
f(n, m)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=[]
R=a.pop()
L=a.pop(0)
s=L
if not a:
    while a[-1]>0:
        r=a.pop()
        ans.append([s,r])
        s=s-r
        if not a:break
ans.append([R,s])
s=R-s
while a:
    L=a.pop()
    ans.append([s,L])
    s=s-L
print(s)
for x in ans:
    print(*x)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=[]
R=a.pop()
L=a.pop(0)
s=L
if a:
    while a[-1]>0:
        r=a.pop()
        ans.append([s,r])
        s=s-r
        if not a:break
ans.append([R,s])
s=R-s
while a:
    L=a.pop()
    ans.append([s,L])
    s=s-L
print(s)
for x in ans:
    print(*x)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=[]
R=a.pop()
L=a.pop(0)
s=L
while a[-1]>0:
    r=a.pop()
    ans.append([s,r])
    s=s-r
    if not a:break
ans.append([R,s])
s=R-s
while a:
    L=a.pop()
    ans.append([s,L])
    s=s-L
print(s)
for x in ans:
    print(*x)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=[]
R=a.pop()
L=a.pop(0)
s=L
if a:
    while a[-1]>0:
        r=a.pop()
        ans.append([s,r])
        s=s-r
        if not a:break
ans.append([R,s])
s=R-s
while a:
    L=a.pop()
    ans.append([s,L])
    s=s-L
print(s)
for x in ans:
    print(*x)
Buggy python submission (verdict: Runtime Error):
import copy

def solve(i, vs, hv):
    if i == 0:
        return sum(hv)
    re = []
    re += [solve(i - 1, vs, hv)]
    re += [solve(i - 1, vs[1:], hv + [vs[0]])]
    re += [solve(i - 1, vs[:-1], hv + [vs[-1]])]
    for hk in hv:
        if hk < 0:
            nhv=copy.deepcopy(hv)
            nhv.remove(hk)
            re += [solve(i - 1, vs + [hk], nhv)]
            re += [solve(i - 1, [hk] + vs, nhv)]
    return max(re)

n, k = map(int, input().split())
vs = list(map(int, input().split()))
print(solve(k, vs, []))


Fixed submission:
def solve(k, koho, cho=[], syo=0):
    if syo == 2:
        lenc=len(cho)
        for i in range(min(k,lenc)):
            mn = min(cho)
            if mn < 0:
                cho.remove(mn)
            else:
                break
        return sum(cho)
    if syo == 1:
        koho = koho[::-1]
    re = []
    lenk = len(koho)
    for i in range(min(k, lenk)+1):
        re.append(solve(k - i, koho[i:], cho+koho[:i], syo + 1))
    return max(re)

n, k = map(int, input().split())
vs = list(map(int, input().split()))
print(solve(k, vs))
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for _ in range(m)]
a.sort()
bc.sort(key=lambda x:-x[1])
br=0
for b,c in bc:
    for _ in range(b):
        a_end=a.pop(0)
        if a_end>=c:
            a.append(a_end)
            br=1
            break
        a.append(c)
    if br:break
print(sum(a))

Fixed submission:
import heapq

n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for _ in range(m)]
heapq.heapify(a)
bc.sort(key=lambda x:-x[1])
br=0
for b,c in bc:
    for _ in range(b):
        a_mn=heapq.heappop(a)
        if a_mn>=c:
            heapq.heappush(a,a_mn)
            br=1
            break
        heapq.heappush(a,c)
    if br:break
print(sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
def com(n,r):
    if n-r<r:
        r=n-r
    re=1
    for i in range(n,n-r,-1):
        re*=i
    for i in range(1,r+1):
        re//=i
    return re

def f(n,m,k):
    md = 10 ** 9 + 7
    ans = 0
    for d in range(1, m):
        ans = (ans + d * (m - d) * n * n) % md
    for d in range(1, n):
        ans = (ans + d * (n - d) * m * m) % md
    ans = (ans * com(n * m - 2, k - 2)) % md
    print(ans)

n,m,k=map(int,input().split())
f(n, m, k)


Fixed submission:
def com(n,r):
    re=fct[n]*pow(fct[r],md-2,md)*pow(fct[n-r],md-2,md)
    re%=md
    return re

n,m,k=map(int,input().split())
md=10**9+7
ans=0
fct=[1]*(n*m-1)
f=1
for i in range(1,n*m-1):
    f=f*i%md
    fct[i]=f
for d in range(1,m):
    ans=(ans+d*(m-d)*n*n)%md
for d in range(1,n):
    ans=(ans+d*(n-d)*m*m)%md
ans=(ans*com(n*m-2,k-2))%md
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def com(n,r):
    if n-r<r:
        r=n-r
    re=1
    for i in range(n,n-r,-1):
        re*=i
    for i in range(1,r+1):
        re//=i
    return re

md=10**9+7
n,m,k=map(int,input().split())
ans=0
for d in range(1,m):
    ans=(ans+d*(m-d)*n*n)%md
for d in range(1,n):
    ans=(ans+d*(n-d)*m*m)%md
ans=(ans*com(n*m-2,k-2))%md
print(ans)


Fixed submission:
def com(n,r):
    re=fct[n]*pow(fct[r],md-2,md)*pow(fct[n-r],md-2,md)
    re%=md
    return re

n,m,k=map(int,input().split())
md=10**9+7
ans=0
fct=[1]*(n*m-1)
f=1
for i in range(1,n*m-1):
    f=f*i%md
    fct[i]=f
for d in range(1,m):
    ans=(ans+d*(m-d)*n*n)%md
for d in range(1,n):
    ans=(ans+d*(n-d)*m*m)%md
ans=(ans*com(n*m-2,k-2))%md
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def com(n,r):
    if n-r<r:
        r=n-r
    re=1
    for i in range(n,n-r,-1):
        re*=i
    for i in range(1,r+1):
        re//=i
    return re

md=10**9+7
n,m,k=map(int,input().split())
ans=0
for d in range(1,m):
    ans+=d*(m-d)*n*n
for d in range(1,n):
    ans+=d*(n-d)*m*m
ans=ans*com(n*m-2,k-2)
print(ans%md)


Fixed submission:
def com(n,r):
    re=fct[n]*pow(fct[r],md-2,md)*pow(fct[n-r],md-2,md)
    re%=md
    return re

n,m,k=map(int,input().split())
md=10**9+7
ans=0
fct=[1]*(n*m-1)
f=1
for i in range(1,n*m-1):
    f=f*i%md
    fct[i]=f
for d in range(1,m):
    ans=(ans+d*(m-d)*n*n)%md
for d in range(1,n):
    ans=(ans+d*(n-d)*m*m)%md
ans=(ans*com(n*m-2,k-2))%md
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import statistics

q=int(input())
a=[]
len_a=0
sum_b=0
for _ in range(q):
    qi=list(map(int,input().split()))
    if qi[0]==1:
        a.append(qi[1])
        sum_b+=qi[2]
        len_a+=1
    else:
        m=statistics.median_low(a)
        print(m,sum_b+sum(abs(x-m) for x in a))


Fixed submission:
# youtube
from heapq import *

q = int(input())
sum_a = 0
sum_b = 0
L = []
R = []
for _ in range(q):
    qi = list(map(int, input().split()))
    if qi[0] == 1:
        a = qi[1]
        heappush(L, -a)
        heappush(R, a)
        if -L[0] > R[0]:
            LtoR = -heappop(L)
            RtoL = heappop(R)
            sum_a += LtoR - RtoL
            heappush(L, -RtoL)
            heappush(R, LtoR)
        sum_b += qi[2]
    else:
        print(-L[0], sum_a + sum_b)
Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n=int(input())
    aa=LI()
    pp=[]
    mm=[]
    for a in aa:
        if a<0:mm.append(a)
        else:pp.append(a)
    if len(mm)%2:
        m=max(mm)
        p=min(pp)
        if p+m>=0:print(sum(pp)-sum(mm)+2*m)
        else:print(sum(pp)-2*p-sum(mm))
    else:
        print(sum(pp)-sum(mm))

main()


Fixed submission:
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())),dtype="i8")
cm = np.sum(a < 0)
a = np.abs(a)
s = np.sum(a)
if cm % 2:
    s -= np.min(a) * 2
print(s)
Buggy python submission (verdict: Runtime Error):
with open("td3") as f:
    open0read = f.read()
n=list(map(int,open0read.split()))
n.sort(key=lambda x:-((x-1)%10))
print(sum([((x-1)//10+1)*10 for x in n[:-1]]+[n[-1]]))


Fixed submission:
n=list(map(int,open(0).read().split()))
n.sort(key=lambda x:-((x-1)%10))
print(sum([((x-1)//10+1)*10 for x in n[:-1]]+[n[-1]]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

an,bn,cn,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
ans=[0]*k
mn=0
bmx=max(b)
cmx=max(c)
for ak in a:
    if ak+bmx+cmx<mn:break
    for bk in b:
        if ak+bk+cmx<mn:break
        for ck in c:
            abc=ak+bk+ck
            if abc<mn:break
            if abc>mn:
                if len(ans)==k:
                    ans.remove(mn)
                ans+=[abc]
                mn=min(ans)
for x in sorted(ans,reverse=True):
    print(x)


Fixed submission:
an, bn, cn, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
la = len(a)
lb = len(b)
lc = len(c)

ans = [a[0] + b[0] + c[0]]
hq = [[a[0] + b[0] + c[0], 0, 0, 0]]
sumi = [[0, 0, 0]]
for _ in range(k - 1):
    mx = hq[0][0]
    ai = hq[0][1]
    bi = hq[0][2]
    ci = hq[0][3]
    hq = hq[1:]
    if ai + 1 < la and [ai + 1, bi, ci] not in sumi:
        hq += [[mx - a[ai] + a[ai + 1], ai + 1, bi, ci]]
        sumi += [[ai + 1, bi, ci]]
    if bi + 1 < lb and [ai, bi + 1, ci] not in sumi:
        hq += [[mx - b[bi] + b[bi + 1], ai, bi + 1, ci]]
        sumi += [[ai, bi + 1, ci]]
    if ci + 1 < lc and [ai, bi, ci + 1] not in sumi:
        hq += [[mx - c[ci] + c[ci + 1], ai, bi, ci + 1]]
        sumi += [[ai, bi, ci + 1]]
    hq.sort(reverse=True)
    ans += [hq[0][0]]

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