qyliang/CodeNanoFix huggingface dataset:
Buggy code:
from operator import mul
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())

N, M = tuple(li())
Cs = []
for i in range(N):
    n = tuple(li())
    Cs.append([-sum(map(abs, n)), n])
# state:  x, y, z, point
state = [0, 0, 0, 0]
maximum = 0
trans = []
for per in range(8):
    ops = [(per&4)>>2, (per&2)>>1, per&1]
    trans.clear()
    for i in range(N):
        trans.append(list(map(mul, Cs[i], ops)))
    tans.sort(key=lambda x: -sum(x))
    maximum = max(maximum, sum(trans[:M]))
        

print(maximum) 


Fixed code:
from operator import mul
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())

N, M = tuple(li())
Cs = []
for i in range(N):
    n = tuple(li())
    Cs.append(n)
# state:  x, y, z, point
state = [0, 0, 0, 0]
maximum = 0
trans = []
for per in range(8):
    ops = [1 if (per&4)>>2 else -1, 1 if (per&2)>>1 else -1, 1 if per&1 else -1]
    trans.clear()
    for i in range(N):
        trans.append(list(map(mul, Cs[i], ops)))
    trans.sort(key=lambda x: -sum(x))
    maximum = max(maximum, sum(sum(t) for t in trans[:M]))
        

print(maximum)
Buggy code:
n,m=map(int,input().split())
x = [list(map(int, input().split())) for _ in range(n)]
from itertools import *
res = 0
for a in product([-1, 1], [-1, 1], [-1, 1]):
    ts =[]
    for t in x:
        t = 0
        for i,j in zip(a,t):
            t+=i*j
        ts.append(t)
    s = sum(sorted(ts,reverse=True)[:m])
    res = max(res, s)
print(res)

Fixed code:
n,m=map(int,input().split())
x = [list(map(int, input().split())) for _ in range(n)]
from itertools import *
res = 0
for a in product([-1, 1], [-1, 1], [-1, 1]):
    ts =[]
    for t in x:
        ta = 0
        for i,j in zip(a,t):
            ta+=i*j
        ts.append(ta)
    s = sum(sorted(ts,reverse=True)[:m])
    res = max(res, s)
print(res)
Buggy code:
N, M = map(int, input().split())
A = [[int(i) for i in input().split()] for i in range(N)]

def f(x):
    if x == 1:
        return 1
    else:
        return 0

ans = 0
for i in range(1 << 3):
    B = []
    for x, y, z in A:
        B.append(f((i >> 2) & 1) * x + f((i >> 1) & 1) * y + f(i & 1) * z)
    B.sort(reverse = True)
    ans = max(ans, sum(B[:M]))
    
print(ans)

Fixed code:
N, M = map(int, input().split())
A = [[int(i) for i in input().split()] for i in range(N)]

def f(x):
    if x == 1:
        return 1
    else:
        return -1

ans = 0
for i in range(1 << 3):
    B = []
    for x, y, z in A:
        B.append(f((i >> 2) & 1) * x + f((i >> 1) & 1) * y + f(i & 1) * z)
    B.sort(reverse = True)
    ans = max(ans, sum(B[:M]))
    
print(ans)
Buggy code:
n, m = list(map(int, input().split(' ')))
x = []
y = []
z = []
for i in range(n):
    a, b, c = list(map(int, input().split(' ')))
    x.append(a)
    y.append(b)
    z.append(c)
    
def maximize(a, b, c):
    ans = sorted(list(range(n)), reverse=True, key=lambda i: a * x[i] + b * y[i] + c * z[i])[:m]
    return sum(a * x[i] + b * y[i] + c * z[i] for i in ans)

ma = -1
for a in [-1, 1]:
    for b in [-1, 1]:
        for c in [-1, 1]:
            ma = max(m, maximize(a, b, c))
print(ma)

Fixed code:
n, m = list(map(int, input().split(' ')))
x = []
y = []
z = []
for i in range(n):
    a, b, c = list(map(int, input().split(' ')))
    x.append(a)
    y.append(b)
    z.append(c)
    
def maximize(a, b, c):
    ans = sorted(list(range(n)), reverse=True, key=lambda i: a * x[i] + b * y[i] + c * z[i])[:m]
    return sum(a * x[i] + b * y[i] + c * z[i] for i in ans)

ma = -1
for a in [-1, 1]:
    for b in [-1, 1]:
        for c in [-1, 1]:
            ma = max(ma, maximize(a, b, c))
print(ma)
Buggy code:
n, m = map(int, input().split())
xyz = [tuple(map(int, input().split())) for _ in range(n)]

s1 = sum([x+y+z for x, y, z in xyz][:m])
s2 = sum([x+y-z for x, y, z in xyz][:m])
s3 = sum([x-y+z for x, y, z in xyz][:m])
s4 = sum([x-y-z for x, y, z in xyz][:m])
s5 = sum([-x+y+z for x, y, z in xyz][:m])
s6 = sum([-x+y-z for x, y, z in xyz][:m])
s7 = sum([-x-y+z for x, y, z in xyz][:m])
s8 = sum([-x-y-z for x, y, z in xyz][:m])

print(max(s1, s2, s3, s4, s5, s6, s7, s8))

Fixed code:
n, m = map(int, input().split())
xyz = [tuple(map(int, input().split())) for _ in range(n)]

s1 = abs(sum(sorted([x+y+z for x, y, z in xyz])[:m]))
s2 = abs(sum(sorted([x+y-z for x, y, z in xyz])[:m]))
s3 = abs(sum(sorted([x-y+z for x, y, z in xyz])[:m]))
s4 = abs(sum(sorted([x-y-z for x, y, z in xyz])[:m]))
s5 = abs(sum(sorted([-x+y+z for x, y, z in xyz])[:m]))
s6 = abs(sum(sorted([-x+y-z for x, y, z in xyz])[:m]))
s7 = abs(sum(sorted([-x-y+z for x, y, z in xyz])[:m]))
s8 = abs(sum(sorted([-x-y-z for x, y, z in xyz])[:m]))

print(max(s1, s2, s3, s4, s5, s6, s7, s8))
Buggy code:
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
dp_ppp=[]
dp_mpp=[]
dp_pmp=[]
dp_ppm=[]
dp_mmp=[]
dp_mpm=[]
dp_pmm=[]
dp_mmm=[]
for i in range(N):
  x,y,z=map(int,input().split())
  dp_ppp.append(x+y+z)
  dp_mpp.append(-x+y+z)
  dp_pmp.append(x-y+z)
  dp_ppm.append(x+y-z)
  dp_mmp.append(-x-y+z)
  dp_mpm.append(-x+y-z)
  dp_pmm.append(x-y-z)
  dp_mmm.append(-x-y-z)
ppp=sum(sorted(dp_ppp)[0:M])
mpp=sum(sorted(dp_mpp)[0:M])
pmp=sum(sorted(dp_pmp)[0:M])
ppm=sum(sorted(dp_ppm)[0:M])
mmp=sum(sorted(dp_mmp)[0:M])
mpm=sum(sorted(dp_mpm)[0:M])
pmm=sum(sorted(dp_pmm)[0:M])
mmm=sum(sorted(dp_mmm)[0:M])
ans=max([ppp,mpp,pmp,ppm,mmp,mpm,pmm,mmm])
print(ans)

Fixed code:
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
dp_ppp=[]
dp_mpp=[]
dp_pmp=[]
dp_ppm=[]
dp_mmp=[]
dp_mpm=[]
dp_pmm=[]
dp_mmm=[]
for i in range(N):
  x,y,z=map(int,input().split())
  dp_ppp.append(x+y+z)
  dp_mpp.append(-x+y+z)
  dp_pmp.append(x-y+z)
  dp_ppm.append(x+y-z)
  dp_mmp.append(-x-y+z)
  dp_mpm.append(-x+y-z)
  dp_pmm.append(x-y-z)
  dp_mmm.append(-x-y-z)
dp_ppp.sort(key=lambda x:-x)
dp_mpp.sort(key=lambda x:-x)
dp_pmp.sort(key=lambda x:-x)
dp_ppm.sort(key=lambda x:-x)
dp_mmp.sort(key=lambda x:-x)
dp_mpm.sort(key=lambda x:-x)
dp_pmm.sort(key=lambda x:-x)
dp_mmm.sort(key=lambda x:-x)
ppp=sum(dp_ppp[0:M])
mpp=sum(dp_mpp[0:M])
pmp=sum(dp_pmp[0:M])
ppm=sum(dp_ppm[0:M])
mmp=sum(dp_mmp[0:M])
mpm=sum(dp_mpm[0:M])
pmm=sum(dp_pmm[0:M])
mmm=sum(dp_mmm[0:M])
ans=max([ppp,mpp,pmp,ppm,mmp,mpm,pmm,mmm])
print(ans)
Buggy code:
N, M = map(int, input().split())
cake = [list(map(int, input().split())) for _ in range(N)]

INF = 10 ** 18
dp = [[[-INF] * 8 for _ in range(M + 1)] for _ in range(N + 1)]
for i in range(8):
    dp[0][0][i] = 0

for i in range(1, N + 1):
    x, y, z = cake[i - 1]
    for j in range(1, M + 1):
        for msk in range(8):
            mx = x * (1 - 2 * (msk >> 2 & 1))
            my = y * (1 - 2 * (msk >> 1 & 1))
            mz = z * (1 - 2 * (msk >> 0 & 1))
            dp[i][j][msk] = max(dp[i - 1][j][msk],
                                dp[i - 1][j - 1][msk] + mx + my + mz)

print(max(dp[N][M][i] for i in range(8)))

Fixed code:
N, M = map(int, input().split())
cake = [list(map(int, input().split())) for _ in range(N)]

INF = 10 ** 18
dp = [[[-INF] * 8 for _ in range(M + 1)] for _ in range(N + 1)]
for i in range(N + 1):
    for msk in range(8):
        dp[i][0][msk] = 0

for i in range(1, N + 1):
    x, y, z = cake[i - 1]
    for j in range(1, M + 1):
        for msk in range(8):
            mx = x * (1 - 2 * (msk >> 2 & 1))
            my = y * (1 - 2 * (msk >> 1 & 1))
            mz = z * (1 - 2 * (msk >> 0 & 1))
            dp[i][j][msk] = max(dp[i - 1][j][msk],
                                dp[i - 1][j - 1][msk] + mx + my + mz)

print(max(dp[N][M][i] for i in range(8)))
Buggy code:
I=lambda:list(map(int,input().split()));n,m=I();s=[I()for _ in[0]*n];a=0
for i in range(1<<3):
 t=[[v for v in t]for t in s]
 for j in range(3):
  for k in range(n):t[k][j]*=-(i>>j&1)
 a=max(a,sum(sorted(sum(j)for j in t)[-m:]))
print(a)

Fixed code:
n,m=map(int,input().split())
s=[list(map(int,input().split()))for _ in range(n)]
a=0
for i in range(1<<3):
    t=[[v for v in s[i]]for i in range(n)]
    for j in range(3):
        if i>>j&1:
            for k in range(n):
                t[k][j]*=-1
    for j in range(n):
        t[j]=sum(t[j])
    a=max(a,sum(sorted(t)[::-1][:m]))
print(a)
Buggy code:
# coding: utf-8
# Your code here!

N, M = map(int, input().split(" "))
x = []
y = []
z = []

for i in range(N):
    _x, _y, _z = map(int, input().split(" "))
    x.append(_x)
    y.append(_y)
    z.append(_z)

ans = 0
a = [
    [1,1,1],
    [1,1,-1],
    [1,-1,1],
    [1,-1,-1],
    [-1,1,1],
    [-1,1,-1],
    [-1,-1,1],
    [-1,-1,-1],
    ]

for i in range(8):
    score = []
    for j in range(N):
        score.append(a[i][0]*x[j]+a[i][1]*y[j]+a[i][2]*z[j])
    score.reverse()

    ret = 0
    for k in range(M):
        ret += score[k]
    ans = max(ans, ret)
print(ans)

Fixed code:
# coding: utf-8
# Your code here!

N, M = map(int, input().split(" "))
x = []
y = []
z = []

for i in range(N):
    _x, _y, _z = map(int, input().split(" "))
    x.append(_x)
    y.append(_y)
    z.append(_z)

ans = 0
a = [
    [1,1,1],
    [1,1,-1],
    [1,-1,1],
    [1,-1,-1],
    [-1,1,1],
    [-1,1,-1],
    [-1,-1,1],
    [-1,-1,-1],
    ]

for i in range(8):
    score = []
    for j in range(N):
        score.append(a[i][0]*x[j]+a[i][1]*y[j]+a[i][2]*z[j])
    score.sort(reverse=True)

    ret = 0
    for k in range(M):
        ret += score[k]
    ans = max(ans, ret)
print(ans)
Buggy code:
N, M = map(int, input().split())
XYZ = [list(map(int, input().split())) for i in range(N)]

if M == 0:
    print(0)
    quit()
else:
    s1 = sorted(XYZ, key=lambda c: c[0] + c[1] + c[2])
    s1max1 = sum(s1[-M:])
    s1max2 = sum(s1[:M])
    s2 = sorted(XYZ, key=lambda c: c[0] + c[1] - c[2])
    s2max1 = sum(s2[-M:])
    s2max2 = sum(s2[:M])
    s3 = sorted(XYZ, key=lambda c: c[0] - c[1] + c[2])
    s3max1 = sum(s3[-M:])
    s3max2 = sum(s3[:M])
    print(max(s1max1, s1max2, s2max1, s2max2, s3max1, s3max2))

Fixed code:
N, M = map(int, input().split())
XYZ = [list(map(int, input().split())) for i in range(N)]

if M == 0:
    print(0)
    quit()
else:
    s1 = sorted(map(lambda c: c[0] + c[1] + c[2], XYZ))
    s1max1 = sum(s1[-M:])
    s1max2 = -sum(s1[:M])
    s2 = sorted(map(lambda c: c[0] + c[1] - c[2], XYZ))
    s2max1 = sum(s2[-M:])
    s2max2 = -sum(s2[:M])
    s3 = sorted(map(lambda c: c[0] - c[1] + c[2], XYZ))
    s3max1 = sum(s3[-M:])
    s3max2 = -sum(s3[:M])
    s4 = sorted(map(lambda c: c[0] - c[1] - c[2], XYZ))
    s4max1 = sum(s4[-M:])
    s4max2 = -sum(s4[:M])
    print(max(s1max1, s1max2, s2max1, s2max2, s3max1, s3max2, s4max1, s4max2))
Buggy code:
N,M=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(N)]
m=0
for j in range(3):
    l=sorted(l,key=lambda x:x[j])[::-1]
    a=abs(sum([i[0] for i in l[:M]]))
    b=abs(sum([i[1] for i in l[:M]]))
    c=abs(sum([i[2] for i in l[:M]]))
    m=max(m,a+b+c)
print(m)


Fixed code:
N,M=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(N)]
s=0
for j in [1,-1]:
    for k in [1,-1]:
        for m in [1,-1]:
            l=sorted(l,key=lambda x:(x[0]*j+x[1]*k+x[2]*m))[::-1]
            a=abs(sum([i[0] for i in l[:M]]))
            b=abs(sum([i[1] for i in l[:M]]))
            c=abs(sum([i[2] for i in l[:M]]))
            s=max(s,a+b+c)
print(s)
Buggy code:
N, M = map(int, input().split(" ")) 
p1 = []
p2 = []
p3 = []
p4 = []
for i in range(N):
  x, y, z = map(int, input().split(" "))
  p1.append(x+y+z)
  p2.append(x+y-z)
  p3.append(x-y+z)
  p4.append(x-y-z)
p1.sort()
p2.sort()
p3.sort()
p4.sort()
a1 = a2 = a3 = a4 = a_1 = a_2 = a_3 = a_4 = 0
for i in range(M):
  a1 += p1[i]
  a2 += p2[i]
  a3 += p3[i]
  a4 += p4[i]
  a_1 += p1[len(p1)-1-i]
  a_2 += p2[len(p2)-1-i]
  a_3 += p3[len(p3)-1-i]
  a_4 += p4[len(p4)-1-i]
ans_re = [a1, a2, a3, a4, a_1, a_2, a_3, a_4]
ans_re.sort()
print(ans_re[7])

Fixed code:
N, M = map(int, input().split(" ")) 
p1 = []
p2 = []
p3 = []
p4 = []
for i in range(N):
  x, y, z = map(int, input().split(" "))
  p1.append(x+y+z)
  p2.append(x+y-z)
  p3.append(x-y+z)
  p4.append(x-y-z)
p1.sort()
p2.sort()
p3.sort()
p4.sort()
a1 = a2 = a3 = a4 = a_1 = a_2 = a_3 = a_4 = 0
for i in range(M):
  a1 += p1[i]
  a2 += p2[i]
  a3 += p3[i]
  a4 += p4[i]
  a_1 += p1[len(p1)-1-i]
  a_2 += p2[len(p2)-1-i]
  a_3 += p3[len(p3)-1-i]
  a_4 += p4[len(p4)-1-i]
ans_re = [-a1, -a2, -a3, -a4, a_1, a_2, a_3, a_4]
ans_re.sort()
print(ans_re[7])
Buggy code:
N, M = map(int, input().split())
x, y, z = [], [], []

for i in range(N):
    xi, yi, zi = map(int, input().split())
    x.append(xi)
    y.append(yi)
    z.append(zi)

bits = [[1,1,1], [1,1,-1], [1,-1,1], [1,-1,-1], [-1,1,1], [-1,1,-1], [-1,-1,1], [-1,-1,-1]]


print(x)
results = []
for i in range(len(bits)):
    xyzsum=[0 for _ in range(N) ]
    for j in range(N):
        xyzsum[j] = (x[j]*bits[0][0] + y[j]*bits[0][1] + z[j]*bits[0][2])

    xyzsum = sorted(xyzsum, reverse=True)
    results.append(xyzsum[:M])

print(sum(max(results)))

Fixed code:
N, M = map(int, input().split())
x, y, z = [], [], []

for i in range(N):
    xi, yi, zi = map(int, input().split())
    x.append(xi)
    y.append(yi)
    z.append(zi)

bits = [[1,1,1], [1,1,-1], [1,-1,1], [1,-1,-1], [-1,1,1], [-1,1,-1], [-1,-1,1], [-1,-1,-1]]


results = []
for i in range(len(bits)):
    xyzsum=[0 for _ in range(N)]
    for j in range(N):
        xyzsum[j] = (x[j]*bits[i][0] + y[j]*bits[i][1] + z[j]*bits[i][2])
    xyzsum = sorted(xyzsum, reverse=True)
    results.append(sum(xyzsum[:M]))

print(max(results))
Buggy code:
import numpy as np

N, M = map(int, input().split())

if M == 0:
    print(0)
    exit()

cakes = np.zeros((N, 3))
for i in range(N):
    cakes[i, :] = list(map(int, input().split()))

Calc = []
temp = np.zeros((N, 3))
tot = np.zeros(N)
for i in range(2):
    temp[:, 0] = cakes[:, 0] * (-1) ** i
    for j in range(2):
        temp[:, 1] = cakes[:, 1] * (-1) ** j
        for k in range(2):
            temp[:, 2] = cakes[:, 2] * (-1) ** k
            tot = np.sort(temp.sum(axis = 1))[::-1]
            print(tot)
            Calc.append(tot[:M].sum())

print(int(max(Calc)))

Fixed code:
import numpy as np

N, M = map(int, input().split())

if M == 0:
    print(0)
    exit()

cakes = np.zeros((N, 3))
for i in range(N):
    cakes[i, :] = list(map(int, input().split()))

Calc = []
temp = np.zeros((N, 3))
tot = np.zeros(N)
for i in range(2):
    temp[:, 0] = cakes[:, 0] * (-1) ** i
    for j in range(2):
        temp[:, 1] = cakes[:, 1] * (-1) ** j
        for k in range(2):
            temp[:, 2] = cakes[:, 2] * (-1) ** k
            tot = np.sort(temp.sum(axis = 1))[::-1]
            Calc.append(tot[:M].sum())

print(int(max(Calc)))
Buggy code:
a = []
b = []
ans = 0
def flip(f):
    for i in range(len(a)):
        for j in range(3):
            if f & (1 << j) == 1:
                a[i][j] = - a[i][j]
n,m = map(int,input().split())
for i in range(n):
    a.append(list(map(int,input().split())))
for f in range(8):
    del(b[:])
    flip(f)
    for x in a:
        b.append(sum(x))
    b.sort(reverse = True)
    ans = max([ans,sum(b[:m])])
    flip(f)
print(ans)


Fixed code:
a = []
b = []
ans = 0
def flip(f):
    for i in range(len(a)):
        for j in range(3):
            if f & (1 << j) != 0:
                a[i][j] = - a[i][j]
n,m = map(int,input().split())
for i in range(n):
    a.append(list(map(int,input().split())))
for f in range(8):
    del(b[:])
    flip(f)
    for x in a:
        b.append(sum(x))
    b.sort(reverse = True)
    ans = max([ans,sum(b[:m])])
    flip(f)
print(ans)
Buggy code:
from itertools import product
N,M = map(int,input().split(" "))
x,y,z = [0]*N,[0]*N,[0]*N
for i in range(N):
	x[i],y[i],z[i] = map(int,input().split(" "))
ans = 0
for a,b,c in product(range(2),repeat=3):
	xyz = [0]*N
	for i in range(N):
		xyz[i] = (xyz[i] + x[i]) if a % 2 == 1 else (xyz[i] - x[i])
		xyz[i] = (xyz[i] + y[i]) if b % 2 == 1 else (xyz[i] - y[i])
		xyz[i] = (xyz[i] + z[i]) if c % 2 == 1 else (xyz[i] - z[i])
		xyz.sort(reverse=True)
		ans = max(sum(xyz[:3]),ans)

print(ans)

Fixed code:
from itertools import product
N,M = map(int,input().split(" "))
x,y,z = [0]*N,[0]*N,[0]*N
for i in range(N):
	x[i],y[i],z[i] = map(int,input().split(" "))
ans = 0
for a,b,c in product(range(2),repeat=3):
	xyz = [0]*N
	for i in range(N):
		xyz[i] = (xyz[i] + x[i]) if a % 2 == 1 else (xyz[i] - x[i])
		xyz[i] = (xyz[i] + y[i]) if b % 2 == 1 else (xyz[i] - y[i])
		xyz[i] = (xyz[i] + z[i]) if c % 2 == 1 else (xyz[i] - z[i])
	xyz.sort(reverse=True)
	ans = max(sum(xyz[:M]),ans)
print(ans)
Buggy code:
n,m = map(int, input().split())
x = [tuple(map(int, input().split())) for _ in range(n)]
from itertools import *
res = 0
for a in product([-1, 1], [-1, 1], [-1, 1]):
  res = max(res, sum(sorted(((sum(i*j for i,j in zip(a,t)) for t in x),reverse=True)[:m]))
print(res)

Fixed code:
n,m = map(int, input().split())
x = [tuple(map(int, input().split())) for _ in range(n)]
from itertools import *
res = 0
for a in product([-1, 1], [-1, 1], [-1, 1]):
  res = max(res, sum(sorted((sum(i*j for i,j in zip(a,t)) for t in x),reverse=True)[:m]))
print(res)
Buggy code:
from itertools import product
t=[]
ans=0
n,m=map(int,input().split())
s=list(product([1,-1],repeat=3))
for i in range(n):
    li=[]
    p,q,r=map(int,input().split())
    for a,b,c in s:
        li.append(a*p+b*q+c*r)
    t+=[li]
for j in list(zip((*t))):
    p=sum(sorted(j)[n-m:])
    ans=max(ans,p)
print(ans)


Fixed code:
from itertools import product
t=[]
ans=0
n,m=map(int,input().split())
s=list(product([1,-1],repeat=3))
for i in range(n):
    li=[]
    p,q,r=map(int,input().split())
    for a,b,c in s:
        li.append(a*p+b*q+c*r)
    t+=[li]
for j in list(zip(*t)):
    p=sum(sorted(j)[n-m:])
    ans=max(ans,p)
print(ans)
Buggy code:
N,M = list(map(int, input().split()))
cakes = []
for i in range(N):
    cakes.append(list(map(int, input().split())))

ans = 0

values = []
for x,y,z in cakes:
    values.append(x+y+z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))

values = []
for x,y,z in cakes:
    values.append(x+y-z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for x,y,z in cakes:
    values.append(x-y+z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for x,y,z in cakes:
    values.append(x-y-z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for x,y,z in cakes:
    values.append(-x+y+z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for x,y,z in cakes:
    values.append(-x+y-z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))



values = []
for x,y,z in cakes:
    values.append(-x-y+z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for x,y,z in cakes:
    values.append(-x-y-z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


print(ans/3)


Fixed code:
N,M = list(map(int, input().split()))
cakes = []
for i in range(N):
    cakes.append(list(map(int, input().split())))

ans = 0

values = []
for x,y,z in cakes:
    values.append(x+y+z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))

values = []
for x,y,z in cakes:
    values.append(x+y-z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for x,y,z in cakes:
    values.append(x-y+z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for x,y,z in cakes:
    values.append(x-y-z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for x,y,z in cakes:
    values.append(-x+y+z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for x,y,z in cakes:
    values.append(-x+y-z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))



values = []
for x,y,z in cakes:
    values.append(-x-y+z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for x,y,z in cakes:
    values.append(-x-y-z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


print(ans)
Buggy code:
n,m = map(int,input().split())
l = [[int(i)for i in input().split()]for _ in [0]*n]

def  g(k):
  a = [x[0]if k&1 else -x[0])+(x[1]if k&2 else -x[1])+(x[2]if k&4 else -x[2])  for x in l]
  a.sort(reverse=True)
  return sum(a[:m])
print(max([g(i) for i range(8)]))

Fixed code:
n,m = map(int,input().split())
l = [[int(i)for i in input().split()]for _ in [0]*n]

def g(k):
  a = [(x[0]if k&1 else -x[0])+(x[1]if k&2 else -x[1])+(x[2]if k&4 else -x[2])  for x in l]
  a.sort(reverse=True)
  return sum(a[:m])
print(max([g(i)for i in range(8)]))
Buggy code:
N,M=map(int,input().split())
P=[]
for i in range(N):
    x,y,z=map(int,input().split())
    P.append([x,y,z])
ans =0
for i in range(8):
    A=[]
    for j in range(N):
        s = 0
        for k in range(3):
            if i& (1<<k):
                s+=P[j][k]
            else:
                s-=P[j][k]
        A.append(s)
    A.sort()
    print(A[-M:])
    ans = max(ans,sum(A[-M:]))
print(ans)

Fixed code:
import sys
N,M=map(int,input().split())
P=[]
for i in range(N):
    x,y,z=map(int,input().split())
    P.append([x,y,z])
if M==0:
    print(0)
    sys.exit()
ans =0
for i in range(8):
    A=[]
    for j in range(N):
        s = 0
        for k in range(3):
            if i& (1<<k):
                s+=P[j][k]
            else:
                s-=P[j][k]
        A.append(s)
    A.sort()
    ans = max(ans,sum(A[-M:]))
print(ans)
Buggy code:
import numpy as np

N, M = map(int, input().split())



num_list = np.zeros((N,3))
for i in range(N):
	num_list[i] = list(map(int, input().split()))

num_list = num_list.T

ans = max(
	np.sum(np.sort(num_list[0,:] + num_list[1,:] + num_list[2,:])[::-1][:M]),
	np.sum(np.sort(num_list[0,:] + num_list[1,:] - num_list[2,:])[::-1][:M]),
	np.sum(np.sort(num_list[0,:] - num_list[1,:] + num_list[2,:])[::-1][:M]),
	np.sum(np.sort(num_list[0,:] - num_list[1,:] - num_list[2,:])[::-1][:M]),
	np.sum(-np.sort(num_list[0,:] + num_list[1,:] + num_list[2,:])[::-1][:M]),
	np.sum(-np.sort(num_list[0,:] + num_list[1,:] - num_list[2,:])[::-1][:M]),
	np.sum(-np.sort(num_list[0,:] - num_list[1,:] + num_list[2,:])[::-1][:M]),
	np.sum(-np.sort(num_list[0,:] - num_list[1,:] - num_list[2,:])[::-1][:M])
)
print(int(ans))


Fixed code:
import numpy as np

N, M = map(int, input().split())



num_list = np.zeros((N,3))
for i in range(N):
	num_list[i] = list(map(int, input().split()))

num_list = num_list.T

ans = max(
	np.sum(np.sort(num_list[0,:] + num_list[1,:] + num_list[2,:])[::-1][:M]),
	np.sum(np.sort(num_list[0,:] + num_list[1,:] - num_list[2,:])[::-1][:M]),
	np.sum(np.sort(num_list[0,:] - num_list[1,:] + num_list[2,:])[::-1][:M]),
	np.sum(np.sort(num_list[0,:] - num_list[1,:] - num_list[2,:])[::-1][:M]),
	np.sum(np.sort(-num_list[0,:] + num_list[1,:] + num_list[2,:])[::-1][:M]),
	np.sum(np.sort(-num_list[0,:] + num_list[1,:] - num_list[2,:])[::-1][:M]),
	np.sum(np.sort(-num_list[0,:] - num_list[1,:] + num_list[2,:])[::-1][:M]),
	np.sum(np.sort(-num_list[0,:] - num_list[1,:] - num_list[2,:])[::-1][:M])
)
print(int(ans))