Buggy python submission (verdict: Runtime Error):
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 submission:
N, M = map(int, input().split())
cakes = []
for i in range(N):
    x, y, z = map(int, input().split())
    cakes.append([x, y, z])


if M == 0:
    print(0)
    quit()
score = [0]*8
s = sorted(map(lambda c: c[0]+c[1]+c[2], cakes))
score[0] = sum(s[-M:])
score[1] = -sum(s[:M])
s = sorted(map(lambda c: c[0]+c[1]-c[2], cakes))
score[2] = sum(s[-M:])
score[3] = -sum(s[:M])
s = sorted(map(lambda c: c[0]-c[1]+c[2], cakes))
score[4] = sum(s[-M:])
score[5] = -sum(s[:M])
s = sorted(map(lambda c: c[0]-c[1]-c[2], cakes))
score[6] = sum(s[-M:])
score[7] = -sum(s[:M])
print(max(score))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
XYZ = [list(map(int, input().split())) for i in range(N)]
X = [XYZ[i][0] for i in range(N)]
Y = [XYZ[i][1] for i in range(N)]
Z = [XYZ[i][2] for i in range(N)]
ans = 0

for i in range(2**M - 1, 2**N - 2**(N - M) + 1):
    b = bin(i)[2:]
    if len(b) != N:
        f = [0 for i in range(N-len(b))] + [int(a) for a in b]
    else:
        f = [int(a) for a in b]
    if sum(f) == M:
        ans_x = abs(sum([x * y for x, y in zip(X, f)]))
        ans_y = abs(sum([x * y for x, y in zip(Y, f)]))
        ans_z = abs(sum([x * y for x, y in zip(Z, f)]))
        ans = max(ans, (ans_x + ans_y + ans_z))

print(ans)

Fixed submission:
N, M = map(int, input().split())
cakes = []
for i in range(N):
    x, y, z = map(int, input().split())
    cakes.append([x, y, z])


if M == 0:
    print(0)
    quit()
score = [0]*8
s = sorted(map(lambda c: c[0]+c[1]+c[2], cakes))
score[0] = sum(s[-M:])
score[1] = -sum(s[:M])
s = sorted(map(lambda c: c[0]+c[1]-c[2], cakes))
score[2] = sum(s[-M:])
score[3] = -sum(s[:M])
s = sorted(map(lambda c: c[0]-c[1]+c[2], cakes))
score[4] = sum(s[-M:])
score[5] = -sum(s[:M])
s = sorted(map(lambda c: c[0]-c[1]-c[2], cakes))
score[6] = sum(s[-M:])
score[7] = -sum(s[:M])
print(max(score))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
XYZ = [list(map(int, input().split())) for i in range(N)]
X = [XYZ[i][0] for i in range(N)]
Y = [XYZ[i][1] for i in range(N)]
Z = [XYZ[i][2] for i in range(N)]
ans = 0

for i in range(2**M - 1, 2**N - 2**(N - M) + 1):
    b = bin(i)[2:]
    if len(b) != N:
        f = [0 for i in range(N-len(b))] + [int(a) for a in b]
    else:
        f = [int(a) for a in b]
    if sum(f) == M:
        ans_x = abs(sum([x * y for x, y in zip(X, f)]))
        ans_y = abs(sum([x * y for x, y in zip(Y, f)]))
        ans_z = abs(sum([x * y for x, y in zip(Z, f)]))
        ans = max(ans, (ans_x + ans_y + ans_z))

print(ans)

Fixed submission:
N, M = map(int, input().split())
cakes = []
for i in range(N):
    x, y, z = map(int, input().split())
    cakes.append([x, y, z])


if M == 0:
    print(0)
    quit()
score = [0]*8
s = sorted(map(lambda c: c[0]+c[1]+c[2], cakes))
score[0] = sum(s[-M:])
score[1] = -sum(s[:M])
s = sorted(map(lambda c: c[0]+c[1]-c[2], cakes))
score[2] = sum(s[-M:])
score[3] = -sum(s[:M])
s = sorted(map(lambda c: c[0]-c[1]+c[2], cakes))
score[4] = sum(s[-M:])
score[5] = -sum(s[:M])
s = sorted(map(lambda c: c[0]-c[1]-c[2], cakes))
score[6] = sum(s[-M:])
score[7] = -sum(s[:M])
print(max(score))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
XYZ = [list(map(int, input().split())) for i in range(N)]
X = [XYZ[i][0] for i in range(N)]
Y = [XYZ[i][1] for i in range(N)]
Z = [XYZ[i][2] for i in range(N)]


import itertools

flag_list = [i for i in range(N)]
flag = itertools.combinations(flag_list, M)
ans = 0
for f in flag:
    ans_x = abs(sum([X[i] for i in f]))
    ans_y = abs(sum([Y[i] for i in f]))
    ans_z = abs(sum([Z[i] for i in f]))
    ans = max(ans, (ans_x + ans_y + ans_z))


print(ans)

Fixed submission:
N, M = map(int, input().split())
cakes = []
for i in range(N):
    x, y, z = map(int, input().split())
    cakes.append([x, y, z])


if M == 0:
    print(0)
    quit()
score = [0]*8
s = sorted(map(lambda c: c[0]+c[1]+c[2], cakes))
score[0] = sum(s[-M:])
score[1] = -sum(s[:M])
s = sorted(map(lambda c: c[0]+c[1]-c[2], cakes))
score[2] = sum(s[-M:])
score[3] = -sum(s[:M])
s = sorted(map(lambda c: c[0]-c[1]+c[2], cakes))
score[4] = sum(s[-M:])
score[5] = -sum(s[:M])
s = sorted(map(lambda c: c[0]-c[1]-c[2], cakes))
score[6] = sum(s[-M:])
score[7] = -sum(s[:M])
print(max(score))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
XYZ = [list(map(int, input().split())) for i in range(N)]
X = [XYZ[i][0] for i in range(N)]
Y = [XYZ[i][1] for i in range(N)]
Z = [XYZ[i][2] for i in range(N)]


import itertools

flag_list = [i for i in range(N)]
flag = itertools.combinations(flag_list, M)
ans = 0
for f in flag:
    ans_x = abs(sum([X[i] for i in f]))
    ans_y = abs(sum([Y[i] for i in f]))
    ans_z = abs(sum([Z[i] for i in f]))
    ans = max(ans, (ans_x + ans_y + ans_z))


print(ans)

Fixed submission:
N, M = map(int, input().split())
cakes = []
for i in range(N):
    x, y, z = map(int, input().split())
    cakes.append([x, y, z])


if M == 0:
    print(0)
    quit()
score = [0]*8
s = sorted(map(lambda c: c[0]+c[1]+c[2], cakes))
score[0] = sum(s[-M:])
score[1] = -sum(s[:M])
s = sorted(map(lambda c: c[0]+c[1]-c[2], cakes))
score[2] = sum(s[-M:])
score[3] = -sum(s[:M])
s = sorted(map(lambda c: c[0]-c[1]+c[2], cakes))
score[4] = sum(s[-M:])
score[5] = -sum(s[:M])
s = sorted(map(lambda c: c[0]-c[1]-c[2], cakes))
score[6] = sum(s[-M:])
score[7] = -sum(s[:M])
print(max(score))