Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
K=int(input())
 
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
 
ans=0
 
for a in range(1,K+1):
    for b in range(1,K+1):
        hoge=gcd(a,b)
        for c in range(1,K+1):
            g=gcd(hoge,c)
            ans += g
 
print(ans)

Fixed submission:
K=int(input())

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

ans=0
re=[1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]

if K < 102:
    for a in range(1,K+1):
        for b in range(1,K+1):
            hoge=gcd(a,b)
            for c in range(1,K+1):
                g=gcd(hoge,c)
                ans += g
else:
    ans=re[K-101]



print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
K=int(input())

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

ans=0

for a in range(1,K+1):
    for b in range(1,K+1):
        hoge=gcd(a,b)
        for c in range(1,K+1):
            g=gcd(hoge,c)
            ans += g

print(ans)

Fixed submission:
K=int(input())

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

ans=0
re=[1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]

if K < 102:
    for a in range(1,K+1):
        for b in range(1,K+1):
            hoge=gcd(a,b)
            for c in range(1,K+1):
                g=gcd(hoge,c)
                ans += g
else:
    ans=re[K-101]



print(ans)
Buggy python submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
arrayP = list(map(int, input().split()))
arrayQ = list(map(int, input().split()))
arrayR = list(map(int, input().split()))
arrayP.sort(reverse=True)
arrayQ.sort(reverse=True)
arrayR.sort(reverse=True)
arrayAns = []
for i in range(x):
    arrayAns.append(int(arrayP[i]))
for i in range(y):
    arrayAns.append(int(arrayQ[i]))
arrayAns.sort()
for i in range(min(len(arrayR), len(arrayAns))):
    if arrayAns[i] <= int(arrayR[i]):
        arrayAns[i] = int(arrayR[i])
    else:
        break
print(sum(arrayAns))

Fixed submission:
S=input()

if S[2]==S[3] and S[4]==S[5]:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
arrayP = list(map(int, input().split()))
arrayQ = list(map(int, input().split()))
arrayR = list(map(int, input().split()))
arrayP.sort(reverse=True)
arrayQ.sort(reverse=True)
arrayR.sort(reverse=True)
arrayAns = []
for i in range(x):
    arrayAns.append(int(arrayP[i]))
for i in range(y):
    arrayAns.append(int(arrayQ[i]))
arrayAns.sort()
for i in range(len(arrayR)):
    if arrayAns[i] <= int(arrayR[i]):
        arrayAns[i] = int(arrayR[i])
    else:
        break
print(sum(arrayAns))

Fixed submission:
S=input()

if S[2]==S[3] and S[4]==S[5]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
arrayP = list(map(int, input().split()))
arrayQ = list(map(int, input().split()))
arrayR = list(map(int, input().split()))
arrayP.sort(reverse=True)
arrayQ.sort(reverse=True)
arrayR.sort(reverse=True)
arrayAns = []
for i in range(x):
    arrayAns.append(int(arrayP[i]))
for i in range(y):
    arrayAns.append(int(arrayQ[i]))
arrayAns.sort()
for i in range(len(arrayR)):
    if arrayAns[i] <= int(arrayR[i]):
        arrayAns[i] = int(arrayR[i])
    else:
        break
print(sum(arrayAns))

Fixed submission:
x, y, a, b, c = map(int, input().split())
arrayP = list(map(int, input().split()))
arrayQ = list(map(int, input().split()))
arrayR = list(map(int, input().split()))
arrayP.sort(reverse=True)
arrayQ.sort(reverse=True)
arrayR.sort(reverse=True)
arrayAns = []
for i in range(x):
    arrayAns.append(int(arrayP[i]))
for i in range(y):
    arrayAns.append(int(arrayQ[i]))
arrayAns.sort()
for i in range(min(len(arrayR), len(arrayAns))):
    if arrayAns[i] <= int(arrayR[i]):
        arrayAns[i] = int(arrayR[i])
    else:
        break
print(sum(arrayAns))

Buggy python submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
arrayP = list(map(int, input().split()))
arrayQ = list(map(int, input().split()))
arrayR = list(map(int, input().split()))
arrayP.sort(reverse=True)
arrayQ.sort(reverse=True)
arrayR.sort(reverse=True)
arrayAns = []
for i in range(x):
    arrayAns.append(int(arrayP[i]))
for i in range(y):
    arrayAns.append(int(arrayQ[i]))
arrayAns.sort()
for i in range(len(arrayAns)):
    if arrayAns[i] <= int(arrayR[i]):
        arrayAns[i] = int(arrayR[i])
    else:
        break
print(sum(arrayAns))

Fixed submission:
x, y, a, b, c = map(int, input().split())
arrayP = list(map(int, input().split()))
arrayQ = list(map(int, input().split()))
arrayR = list(map(int, input().split()))
arrayP.sort(reverse=True)
arrayQ.sort(reverse=True)
arrayR.sort(reverse=True)
arrayAns = []
for i in range(x):
    arrayAns.append(int(arrayP[i]))
for i in range(y):
    arrayAns.append(int(arrayQ[i]))
arrayAns.sort()
for i in range(min(len(arrayR), len(arrayAns))):
    if arrayAns[i] <= int(arrayR[i]):
        arrayAns[i] = int(arrayR[i])
    else:
        break
print(sum(arrayAns))
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
 
r=sum(A[0:K])
re=r
for i in range(N-K):
    r=r+A[K+i]-A[i]
    if r > re:
        re=r
        
print((re+K)/2)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

hoge=0
for i in range(K):
    hoge += A[i]

re=hoge
for i in range(N-K):
    hoge=hoge+A[K+i]-A[i]
    if hoge >= re:
        re=hoge
        
print((re+K)/2)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))

r=sum(A[0:K])
re=r
for i in range(N-K):
    r=r+A[K+i]-A[i]
    if r > re:
        re=r
        
print((re+K)/2)


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

hoge=0
for i in range(K):
    hoge += A[i]

re=hoge
for i in range(N-K):
    hoge=hoge+A[K+i]-A[i]
    if hoge >= re:
        re=hoge
        
print((re+K)/2)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
A =[ list(map(int,input().split())) for i in range(n)]
A.sort(key=lambda x: x[1])
dp=[0]*(m+1)
ans = 0
for i in range(n):
    k=m-A[n-1-i][0]
    while True:
        if k < 0:
            break
        elif dp[k] ==0:
            dp[k] =1
            ans += A[n-1-i][1]
            break
        else:
            k -= 1
        
print(ans)


Fixed submission:
import heapq

N,M = map(int,input().split())
s = [list(map(int, input().split())) for _ in range(N)]
jobs = [[] for _ in range(M)]

for i in s:
    if i[0] <= M:
        jobs[i[0]-1].append(-i[1])

condidate=[]
rewards=0
for k in range(M):
    for reward in jobs[k]:
        heapq.heappush(condidate, reward)
    if len(condidate) > 0:
        reward = heapq.heappop(condidate)
        rewards += -reward

print(rewards)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A= [input() for i in range(N)]

normal = max(A)
maxindex = [i for i, x in enumerate(A) if x == max(A)]
A.remove(normal)
exception = max(A)

for i in range(N):
    if i in maxindex:
        print(exception)
    else:
        print(normal)

Fixed submission:
N = int(input())
A=[int(input()) for i in range(N)]

normal = max(A)
hoge=sorted(A)
exception = hoge[-2]

for i in range(N):
    if A[i] == normal:
        print(exception)
    else:
        print(normal)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A= [input() for i in range(N)]

for i in range(N):
    hoge = A.pop(i)
    print(max(A))
    A.insert(i,hoge)
    

Fixed submission:
N = int(input())
A=[int(input()) for i in range(N)]

normal = max(A)
hoge=sorted(A)
exception = hoge[-2]

for i in range(N):
    if A[i] == normal:
        print(exception)
    else:
        print(normal)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
ans = [0]*N

def bai_sum(A,n):
    global N
    sumup = 0
    for i in range(int(N/n)):
        sumup += A[n*(i+1)-1]
    return sumup % 2


for i in reversed(range(N)):
    if bai_sum(ans,(i+1)) != A[i]:
        ans[i] = 1
        
print(ans.count(1))

b=''
for i in range(N):
    if ans[i]==1 :
        hoge = i+1
        b = b+str(hoge)+' '

print(b)

Fixed submission:
import math
N=int(input())
A = list(map(int,input().split()))
s = [0]*N
ans=0

for i in reversed(range(N)):
    floor = math.floor(N/(i+1))
    sum=0
    for k in range(1,floor+1):

        sum+=s[((i+1)*k)-1]
    if (sum - A[i])%2 == 1:
        s[i] = 1
        ans+=1

print(ans)
for i in range(N):
    if s[i] == 1:
        print(i+1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
ans = [0]*N

def bai_sum(A,n):
    global N
    sumup = 0
    for i in range(int(N/n)):
        sumup += A[n*(i+1)-1]
    return sumup % 2


for i in reversed(range(N)):
    if bai_sum(ans,(i+1)) != A[i]:
        ans[i] = 1
        
print(ans.count(1))

b=''
for i in range(N):
    if ans[i]==1 :
        hoge = i+1
        b = b+str(hoge)+' '

print(b)

Fixed submission:
import math
N=int(input())
A = list(map(int,input().split()))
s = [0]*N
ans=0

for i in reversed(range(N)):
    floor = math.floor(N/(i+1))
    sum=0
    for k in range(1,floor+1):

        sum+=s[((i+1)*k)-1]
    if (sum - A[i])%2 == 1:
        s[i] = 1
        ans+=1

print(ans)
for i in range(N):
    if s[i] == 1:
        print(i+1)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
blue = k
red = n-k

from scipy.special import comb


for i in range(1,k+1):
    ans = int( (comb(blue - 1 ,i-1)% (10**9 + 7)) * (comb (red + 1 , i)% (10**9 + 7)))
    print(ans % (10**9 + 7))



Fixed submission:
n,k = map(int,input().split())
blue = k
red = n-k

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


for i in range(1,k+1):
    if red < i-1 :
        ans = 0
    else:
        ans = int( cmb(blue - 1 ,i-1)* cmb (red + 1 , i))
    print(ans % (10**9 + 7))

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
blue = k
red = n-k

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

for i in range(1,k+1):
    ans = cmb(blue - 1 ,i-1) * cmb (red + 1 , i)
    print(ans % (10**9 + 7))



Fixed submission:
n,k = map(int,input().split())
blue = k
red = n-k

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


for i in range(1,k+1):
    if red < i-1 :
        ans = 0
    else:
        ans = int( cmb(blue - 1 ,i-1)* cmb (red + 1 , i))
    print(ans % (10**9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(20000000)
input=sys.stdin.readline
N=int(input())

G = [[-1 for i in range(N)] for j in range(N)]
color = [0]*N

for i in range(N-1):
    e,f,g = list(map(int, input().split()))
    G[e-1][f-1]=g%2
    G[f-1][e-1]=g%2

def dfs(v,p,c):
    color[v]=c
    for i in range(N):
        if i==p:
            continue
        elif G[v][i] ==0 :
            dfs(i,v,c)
        elif G[v][i] ==1 :
            dfs(i,v,1-c)
        
dfs(0,-1,0)

for k in color:
    print(k)


Fixed submission:
import sys
sys.setrecursionlimit(2000000)
input=sys.stdin.readline
import heapq

N=int(input())

G = [[] for j in range(N)]

color = [0]*N

for _ in range(N-1):
    e,f,g = list(map(int, input().split()))
    heapq.heappush(G[e-1], [f-1,g%2])
    heapq.heappush(G[f-1], [e-1,g%2])

def dfs(v,p,c):
    color[v]=c
    for k in range(len(G[v])):
        i,j = heapq.heappop(G[v])
        if i==p:
            continue
        elif j ==0 :
            dfs(i,v,c)
        elif j ==1 :
            dfs(i,v,1-c)
        
dfs(0,-1,0)

for k in color:
    print(k)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(20000000)
N=int(input())

G = [[-1 for i in range(N)] for j in range(N)]
color = [0]*N

for i in range(N-1):
    e,f,g = list(map(int, input().split()))
    G[e-1][f-1]=g%2
    G[f-1][e-1]=g%2

def dfs(v,p,c):
    color[v]=c
    for i in range(N):
        if i==p:
            continue
        elif G[v][i] ==0 :
            dfs(i,v,c)
        elif G[v][i] ==1 :
            dfs(i,v,1-c)
        
dfs(0,-1,0)

for k in color:
    print(k)


Fixed submission:
import sys
sys.setrecursionlimit(2000000)
input=sys.stdin.readline
import heapq

N=int(input())

G = [[] for j in range(N)]

color = [0]*N

for _ in range(N-1):
    e,f,g = list(map(int, input().split()))
    heapq.heappush(G[e-1], [f-1,g%2])
    heapq.heappush(G[f-1], [e-1,g%2])

def dfs(v,p,c):
    color[v]=c
    for k in range(len(G[v])):
        i,j = heapq.heappop(G[v])
        if i==p:
            continue
        elif j ==0 :
            dfs(i,v,c)
        elif j ==1 :
            dfs(i,v,1-c)
        
dfs(0,-1,0)

for k in color:
    print(k)
Buggy python submission (verdict: Runtime Error):
N = int(input())
  2 V=list(map(int,input().split()))
  3 C=list(map(int,input().split()))
  4 output = 0
  5 for i in range(N):
  6     if V[i]-C[i] >= 0:
  7         output +=V[i]-C[i]
  8
  9 print(output)

Fixed submission:
N = int(input())
V=list(map(int,input().split()))
C=list(map(int,input().split()))
output = 0
for i in range(N):
    if V[i]-C[i] >= 0:
        output +=V[i]-C[i]

print(output)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A = list(map(int, input().split()))

inf=float('inf')
dp=[[inf]*2 for j in range(N+1)]

def chmax(a,b):
    return max(a,b)

def rec(n,m):
    if n==0 and m==0:
        dp[0][0]=0
        return 0
    if n==0 and m==1:
        dp[0][1]=-inf
        return -inf

    if dp[n][m] < inf:
        return dp[n][m]
    
    if m==0:
        res=chmax(rec(n-1,0)+A[n-1] ,rec(n-1,1)-A[n-1] ) 
    if m==1:
        res=chmax(rec(n-1,0)-A[n-1] ,rec(n-1,1)+A[n-1] )
     
    dp[n][m]=res

    return res

print(rec(N,0))

Fixed submission:
N=int(input())
A = list(map(int, input().split()))
ans=0
tmp=0
hoge=0
li=[]

for i in range(N):
    li.append(abs(A[i]))
    ans+=abs(A[i])
    if A[i]<0:
        tmp+=1
    if A[i]==0:
        hoge=1

if tmp%2==0 or hoge==1:
    ans=ans
else:
    ans=ans-2*min(li)

print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A = list(map(int, input().split()))
inf=float('inf')
dp=[inf]*N

def chmin(a,b):
    return min(a,b)

def rec(n):
    if n==0:
        return 0
    if dp[n] < inf:
        return dp[n]
    
    res=rec(n-1) + abs(A[n] - A[n-1])
    if n>1:
        res=chmin(res,rec(n-2) + abs(A[n] - A[n-2]))
    dp[n]=res
    return res

print(rec(N-1))

Fixed submission:
#最初に置いておくもの
import sys
sys.setrecursionlimit(500000) 
input=sys.stdin.readline


N=int(input())
A = list(map(int, input().split()))
inf=float('inf')
dp=[inf]*N

def chmin(a,b):
    return min(a,b)

def rec(n):
    if n==0:
        return 0
    if dp[n] < inf:
        return dp[n]
    
    res=rec(n-1) + abs(A[n] - A[n-1])
    if n>1:
        res=chmin(res,rec(n-2) + abs(A[n] - A[n-2]))
    dp[n]=res
    return res

print(rec(N-1))
Buggy python submission (verdict: Time Limit Exceeded):
#最初に置いておくもの
import sys
sys.setrecursionlimit(500000) 
input=sys.stdin.readline

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

inf=float('inf')
dp=[[0]*3 for j in range(N+1)]

def chmax(a,b):
    return max(a,b)

def rec(n,m):
    if n==0:
        return 0
    if dp[n][m]>0:
        return dp[n][m]

    for i in range(3):
            if (i == m):
                continue
            dp[n][m]=chmax(dp[n][m], rec(n-1,i) + A[n-1][m])
    
    return dp[n][m]

re=max(rec(N,0),rec(N,1),rec(N,2))
print(re)

Fixed submission:
#最初に置いておくもの
import sys
sys.setrecursionlimit(500000) 
input=sys.stdin.readline

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

inf=float('inf')
dp=[[0]*3 for j in range(N+1)]

def chmax(a,b):
    return max(a,b)

def rec(n,m):
    if n==0:
        return 0
    if dp[n][m]>0:
        return dp[n][m]

    for i in range(3):
            if (i == m):
                continue
            dp[n][m]=chmax(dp[n][m], rec(n-1,i) + A[n-1][m])
    
    return dp[n][m]

re=max(rec(N,0),rec(N,1),rec(N,2))
print(re)

Buggy python submission (verdict: Time Limit Exceeded):
#最初に置いておくもの
import sys
sys.setrecursionlimit(500000) 
input=sys.stdin.readline

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

inf=float('inf')
dp=[[-inf]*3 for j in range(N+1)]
dp[0][0]=0
dp[0][1]=0
dp[0][2]=0

def chmax(a,b):
    return max(a,b)

def rec(n,m):
    if n==0:
        return 0
    for i in range(3):
        if (m == i):
            continue
        dp[n][m]=chmax(dp[n][m], rec(n-1,i) + A[n-1][m])
    
    return dp[n][m]

re=max(rec(N,0),rec(N,1),rec(N,2))
print(re)

Fixed submission:
#最初に置いておくもの
import sys
sys.setrecursionlimit(500000) 
input=sys.stdin.readline

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

inf=float('inf')
dp=[[0]*3 for j in range(N+1)]

def chmax(a,b):
    return max(a,b)

def rec(n,m):
    if n==0:
        return 0
    if dp[n][m]>0:
        return dp[n][m]

    for i in range(3):
            if (i == m):
                continue
            dp[n][m]=chmax(dp[n][m], rec(n-1,i) + A[n-1][m])
    
    return dp[n][m]

re=max(rec(N,0),rec(N,1),rec(N,2))
print(re)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]

ans=0

for i in range(2 **N):
    x=0
    y=0
    z=0
    t=0

    for j in range(N):
        if ((i >> j) & 1):
            x += S[j][0]
            y += S[j][1]
            z += S[j][2]
            t += 1
            if t > M:
                break

    hoge = abs(x) + abs(y) + abs(z)
    if hoge > ans and t==M:
        ans=hoge

print(ans)

Fixed submission:
N,M=map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]
import copy
import heapq
ans=0

for i in range(8):
    li=[]
    heapq.heapify(li)
    hoge=[1,1,1]

    for j in range(3):
        if ((i >> j) & 1):
            hoge[j]=-1
    for k in range(N):
        tmp=0
        for r in range(3):
            tmp += S[k][r] * hoge[r]
        heapq.heappush(li, tmp)
    re=0
    for t in range(M):
        re += heapq.heappop(li)

    re = abs(re)
    if re > ans :
        ans=re

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]

ans=0

for i in range(2 **N):
    x=0
    y=0
    z=0
    t=0

    for j in range(N):
        if ((i >> j) & 1):
            x += S[j][0]
            y += S[j][1]
            z += S[j][2]
            t += 1

    hoge = abs(x) + abs(y) + abs(z)
    if hoge > ans and t==M:
        ans=hoge

print(ans)

Fixed submission:
N,M=map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]
import copy
import heapq
ans=0

for i in range(8):
    li=[]
    heapq.heapify(li)
    hoge=[1,1,1]

    for j in range(3):
        if ((i >> j) & 1):
            hoge[j]=-1
    for k in range(N):
        tmp=0
        for r in range(3):
            tmp += S[k][r] * hoge[r]
        heapq.heappush(li, tmp)
    re=0
    for t in range(M):
        re += heapq.heappop(li)

    re = abs(re)
    if re > ans :
        ans=re

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]

ans=0

for i in range(2 **N):
    x=0
    y=0
    z=0
    t=0

    for j in range(N):
        if ((i >> j) & 1):
            x += S[j][0]
            y += S[j][1]
            z += S[j][2]
            t += 1

    hoge = abs(x) + abs(y) + abs(z)
    if hoge > ans and t==M:
        ans=hoge

print(ans)

Fixed submission:
N,M=map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]
import copy
import heapq
ans=0

for i in range(8):
    li=[]
    heapq.heapify(li)
    hoge=[1,1,1]

    for j in range(3):
        if ((i >> j) & 1):
            hoge[j]=-1
    for k in range(N):
        tmp=0
        for r in range(3):
            tmp += S[k][r] * hoge[r]
        heapq.heappush(li, tmp)
    re=0
    for t in range(M):
        re += heapq.heappop(li)

    re = abs(re)
    if re > ans :
        ans=re

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans=0
B=[0]
for i in range(N):
    B.append(B[i]+A[i])

for k in range(N):
    for j in range(k+1,N+1):
        if B[j]-B[k]==0:
            ans+=1

print(ans)

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

ans=0
B=[0]
for i in range(N):
    B.append(B[i]+A[i])

import collections
dic=dict(collections.Counter(B))

C=list(dic.values())

for k in C:
    if k >=2:
        ans += k*(k-1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans=0
B=[0]
for i in range(N):
    B.append(B[i]+A[i])

for k in range(N):
    for j in range(k+1,N+1):
        if B[j]-B[k]==0:
            ans+=1

print(ans)

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

ans=0
B=[0]
for i in range(N):
    B.append(B[i]+A[i])

import collections
dic=dict(collections.Counter(B))

C=list(dic.values())

for k in C:
    if k >=2:
        ans += k*(k-1) // 2

print(ans)