Buggy python submission (verdict: Runtime Error):
import numpy as np

(N, M) = map(int, raw_input().split())
cakes = [map(int, raw_input().split()) for i in xrange(N)]
cakes_p = np.array(sorted(cakes, key=lambda x: sum(x))[::-1])
cakes_nx = np.array(sorted(cakes, key=lambda x: sum(x) - 2 * x[0])[::-1])
cakes_ny = np.array(sorted(cakes, key=lambda x: sum(x) - 2 * x[1])[::-1])
cakes_nz = np.array(sorted(cakes, key=lambda x: sum(x) - 2 * x[2])[::-1])
cakes_list = [cakes_p, cakes_nx, cakes_ny, cakes_nz, cakes_p[::-1], cakes_nx[::-1], cakes_ny[::-1], cakes_nz[::-1]]
value = max([sum(map(abs,sum(cake[:M]))) for cake in cakes_list])

print value

Fixed submission:
import numpy as np

(N, M) = map(int, raw_input().split())
cakes = [map(int, raw_input().split()) for i in xrange(N)]
cakes_p = np.array(sorted(cakes, key=lambda x: sum(x))[::-1])
cakes_nx = np.array(sorted(cakes, key=lambda x: sum(x) - 2 * x[0])[::-1])
cakes_ny = np.array(sorted(cakes, key=lambda x: sum(x) - 2 * x[1])[::-1])
cakes_nz = np.array(sorted(cakes, key=lambda x: sum(x) - 2 * x[2])[::-1])
cakes_list = [cakes_p, cakes_nx, cakes_ny, cakes_nz, cakes_p[::-1], cakes_nx[::-1], cakes_ny[::-1], cakes_nz[::-1]]
value = max([sum(map(abs,sum(cake[:M]))) for cake in cakes_list]) if M != 0 else 0

print value

Buggy python submission (verdict: Runtime Error):
import numpy as np
(N, M) = map(int, raw_input().split())
cakes = [map(int, raw_input().split()) for i in xrange(N)]
cakes_x = sorted(cakes, key=lambda x: x[0])
cakes_y = sorted(cakes, key=lambda x: x[1])
cakes_z = sorted(cakes, key=lambda x: x[2])

x_min = np.array([0, 0, 0])
x_max = np.array([0, 0, 0])
y_min = np.array([0, 0, 0])
y_max = np.array([0, 0, 0])
z_min = np.array([0, 0, 0])
z_max = np.array([0, 0, 0])
for i in xrange(M):
  x_min += np.array(cakes_x[M])
  x_max += np.array(cakes_x[-M-1])
  y_min += np.array(cakes_y[M])
  y_max += np.array(cakes_y[-M-1])
  z_min += np.array(cakes_z[M])
  z_max += np.array(cakes_z[-M-1])

value = max([sum(map(abs, x_min)), sum(map(abs, x_max)), sum(map(abs, y_min)), sum(map(abs, y_max)), sum(map(abs, z_min)), sum(map(abs, z_max))]
  
print value

Fixed submission:
import numpy as np

(N, M) = map(int, raw_input().split())
cakes = [map(int, raw_input().split()) for i in xrange(N)]
cakes_p = np.array(sorted(cakes, key=lambda x: sum(x))[::-1])
cakes_nx = np.array(sorted(cakes, key=lambda x: sum(x) - 2 * x[0])[::-1])
cakes_ny = np.array(sorted(cakes, key=lambda x: sum(x) - 2 * x[1])[::-1])
cakes_nz = np.array(sorted(cakes, key=lambda x: sum(x) - 2 * x[2])[::-1])
cakes_list = [cakes_p, cakes_nx, cakes_ny, cakes_nz, cakes_p[::-1], cakes_nx[::-1], cakes_ny[::-1], cakes_nz[::-1]]
value = max([sum(map(abs,sum(cake[:M]))) for cake in cakes_list]) if M != 0 else 0

print value

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

(N, M) = map(int, raw_input().split())
cakes = [map(int, raw_input().split()) for i in xrange(N)]
C = itertools.combinations(cakes, M)

i = 0
value = 0
for cake_set in C:
  x = 0
  y = 0
  z = 0
  for j in xrange(M):
    x += cake_set[j][0]
    y += cake_set[j][1]
    z += cake_set[j][2]
  v = abs(x) + abs(y) + abs(z)
  if i == 0 or value < v:
    value = v
  i += 1
  
print value

Fixed submission:
import numpy as np

(N, M) = map(int, raw_input().split())
cakes = [map(int, raw_input().split()) for i in xrange(N)]
cakes_p = np.array(sorted(cakes, key=lambda x: sum(x))[::-1])
cakes_nx = np.array(sorted(cakes, key=lambda x: sum(x) - 2 * x[0])[::-1])
cakes_ny = np.array(sorted(cakes, key=lambda x: sum(x) - 2 * x[1])[::-1])
cakes_nz = np.array(sorted(cakes, key=lambda x: sum(x) - 2 * x[2])[::-1])
cakes_list = [cakes_p, cakes_nx, cakes_ny, cakes_nz, cakes_p[::-1], cakes_nx[::-1], cakes_ny[::-1], cakes_nz[::-1]]
value = max([sum(map(abs,sum(cake[:M]))) for cake in cakes_list]) if M != 0 else 0

print value