Buggy python submission (verdict: Runtime Error):
import itertools
N, M = map(int, input().strip().split())
prev_cakes = []

for _ in range(M - 1):
  prev_cakes.append(tuple(map(int, input().strip().split())))

max_sum = None
for _ in range(N - M + 1):
  cake = tuple(map(int, input().strip().split()))
  for combi_cakes in itertools.combinations(prev_cakes, M - 1):
    print(combi_cakes)
    x = sum([ccake[0] for ccake in combi_cakes]) + cake[0]
    y = sum([ccake[1] for ccake in combi_cakes]) + cake[1]
    z = sum([ccake[2] for ccake in combi_cakes]) + cake[2]
    if max_sum is None or abs(x)+abs(y)+abs(z) > max_sum:
      max_sum = abs(x)+abs(y)+abs(z)
  prev_cakes.append(cake)
print(max_sum)

Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
import itertools

N, M = map(int, input().strip().split())
cakes = []

for _ in range(N):
  cakes.append(tuple(map(int, input().strip().split())))

max_sum = None
for cakes_combi in itertools.combinations(cakes, M):
  x, y, z = 0, 0, 0
  for cake in cakes_combi:
    x += cake[0]
    y += cake[1]
    z += cake[2]
  if max_sum is None or abs(x) + abs(y) + abs(z) > max_sum:
    max_sum = abs(x) + abs(y) + abs(z)
print(max_sum)
  

Fixed submission:
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 python submission (verdict: Runtime Error):
import itertools
 
N, M = map(int, input().strip().split())
cakes = []
 
for _ in range(N):
  cake = list(map(int, input().strip().split()))
  cakes.append(abs(cake[0]) + abs(cake[1]) + abs(cake[2]))
  
print(sum(list(sorted(cakes, key=lambda x: -x)))[:M])

Fixed submission:
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))