Buggy python submission (verdict: Runtime Error):
import functools  # Python3 
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())

ppp = sorted([ x[i]+y[i]+z[i] for i in range(N)])[-M:]
pmp = sorted([ x[i]-y[i]+z[i] for i in range(N)])[-M:]
ppm = sorted([ x[i]+y[i]-z[i] for i in range(N)])[-M:]
pmm = sorted([ x[i]-y[i]-z[i] for i in range(N)])[-M:]
mpp = sorted([-x[i]+y[i]+z[i] for i in range(N)])[-M:]
mpm = sorted([-x[i]+y[i]-z[i] for i in range(N)])[-M:]
mmp = sorted([-x[i]-y[i]+z[i] for i in range(N)])[-M:]
mmm = sorted([-x[i]-y[i]-z[i] for i in range(N)])[-M:]

MAX = 0
for lis in [ppp,pmp,ppm,pmm,mpp,mpm,mmp,mmm]:
	cur = functools.reduce(lambda x,y: x+y,lis)
		MAX = cur
print(MAX)




Fixed submission:
import functools  # Python3 
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())

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

ppp = functools.reduce(lambda x,y: x+y,sorted([ x[i]+y[i]+z[i] for i in range(N)])[-M:])
pmp = functools.reduce(lambda x,y: x+y,sorted([ x[i]-y[i]+z[i] for i in range(N)])[-M:])
ppm = functools.reduce(lambda x,y: x+y,sorted([ x[i]+y[i]-z[i] for i in range(N)])[-M:])
pmm = functools.reduce(lambda x,y: x+y,sorted([ x[i]-y[i]-z[i] for i in range(N)])[-M:])
mpp = functools.reduce(lambda x,y: x+y,sorted([-x[i]+y[i]+z[i] for i in range(N)])[-M:])
mpm = functools.reduce(lambda x,y: x+y,sorted([-x[i]+y[i]-z[i] for i in range(N)])[-M:])
mmp = functools.reduce(lambda x,y: x+y,sorted([-x[i]-y[i]+z[i] for i in range(N)])[-M:])
mmm = functools.reduce(lambda x,y: x+y,sorted([-x[i]-y[i]-z[i] for i in range(N)])[-M:])

MAX = 0
for lis in [ppp,pmp,ppm,pmm,mpp,mpm,mmp,mmm]:
	if lis  > MAX:
		MAX = lis
print(MAX)

Buggy python submission (verdict: Runtime Error):
import functools  # Python3 
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())

ppp = sorted([ x[i]+y[i]+z[i] for i in range(N)])[-M:]
pmp = sorted([ x[i]-y[i]+z[i] for i in range(N)])[-M:]
ppm = sorted([ x[i]+y[i]-z[i] for i in range(N)])[-M:]
pmm = sorted([ x[i]-y[i]-z[i] for i in range(N)])[-M:]
mpp = sorted([-x[i]+y[i]+z[i] for i in range(N)])[-M:]
mpm = sorted([-x[i]+y[i]-z[i] for i in range(N)])[-M:]
mmp = sorted([-x[i]-y[i]+z[i] for i in range(N)])[-M:]
mmm = sorted([-x[i]-y[i]-z[i] for i in range(N)])[-M:]

MAX = 0
for lis in [ppp,pmp,ppm,pmm,mpp,mpm,mmp,mmm]:
	cur = functools.reduce(lambda x,y: x+y,filter(lambda t: t >= 0,lis))
	if cur > MAX:
		MAX = cur
print(MAX)


Fixed submission:
import functools  # Python3 
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())

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

ppp = functools.reduce(lambda x,y: x+y,sorted([ x[i]+y[i]+z[i] for i in range(N)])[-M:])
pmp = functools.reduce(lambda x,y: x+y,sorted([ x[i]-y[i]+z[i] for i in range(N)])[-M:])
ppm = functools.reduce(lambda x,y: x+y,sorted([ x[i]+y[i]-z[i] for i in range(N)])[-M:])
pmm = functools.reduce(lambda x,y: x+y,sorted([ x[i]-y[i]-z[i] for i in range(N)])[-M:])
mpp = functools.reduce(lambda x,y: x+y,sorted([-x[i]+y[i]+z[i] for i in range(N)])[-M:])
mpm = functools.reduce(lambda x,y: x+y,sorted([-x[i]+y[i]-z[i] for i in range(N)])[-M:])
mmp = functools.reduce(lambda x,y: x+y,sorted([-x[i]-y[i]+z[i] for i in range(N)])[-M:])
mmm = functools.reduce(lambda x,y: x+y,sorted([-x[i]-y[i]-z[i] for i in range(N)])[-M:])

MAX = 0
for lis in [ppp,pmp,ppm,pmm,mpp,mpm,mmp,mmm]:
	if lis  > MAX:
		MAX = lis
print(MAX)

Buggy python submission (verdict: Runtime Error):
import functools  # Python3 
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())

# N, M = 5, 3
# x = [1, -4, 7, -10, 13]
# y = [-2, 5, -8, 11, -14]
# z = [3, -6, -9, -12, 15]
ppp = [ x[i]+y[i]+z[i] for i in range(N)]
pmp = [ x[i]-y[i]+z[i] for i in range(N)]
ppm = [ x[i]+y[i]-z[i] for i in range(N)]
pmm = [ x[i]-y[i]-z[i] for i in range(N)]
mpp = [-x[i]+y[i]+z[i] for i in range(N)]
mpm = [-x[i]+y[i]-z[i] for i in range(N)]
mmp = [-x[i]-y[i]+z[i] for i in range(N)]
mmm = [-x[i]-y[i]-z[i] for i in range(N)]

MAX = 0
for lis in [ppp,pmp,ppm,pmm,mpp,mpm,mmp,mmm]:
	cur = functools.reduce(lambda x,y: x+y,filter(lambda t: t >= 0,lis))
	if cur > MAX:
		MAX = cur
print(MAX)


Fixed submission:
import functools  # Python3 
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())

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

ppp = functools.reduce(lambda x,y: x+y,sorted([ x[i]+y[i]+z[i] for i in range(N)])[-M:])
pmp = functools.reduce(lambda x,y: x+y,sorted([ x[i]-y[i]+z[i] for i in range(N)])[-M:])
ppm = functools.reduce(lambda x,y: x+y,sorted([ x[i]+y[i]-z[i] for i in range(N)])[-M:])
pmm = functools.reduce(lambda x,y: x+y,sorted([ x[i]-y[i]-z[i] for i in range(N)])[-M:])
mpp = functools.reduce(lambda x,y: x+y,sorted([-x[i]+y[i]+z[i] for i in range(N)])[-M:])
mpm = functools.reduce(lambda x,y: x+y,sorted([-x[i]+y[i]-z[i] for i in range(N)])[-M:])
mmp = functools.reduce(lambda x,y: x+y,sorted([-x[i]-y[i]+z[i] for i in range(N)])[-M:])
mmm = functools.reduce(lambda x,y: x+y,sorted([-x[i]-y[i]-z[i] for i in range(N)])[-M:])

MAX = 0
for lis in [ppp,pmp,ppm,pmm,mpp,mpm,mmp,mmm]:
	if lis  > MAX:
		MAX = lis
print(MAX)

Buggy python submission (verdict: Runtime Error):
import functools  # Python3 
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())

# N, M = 5, 3
# x = [1, -4, 7, -10, 13]
# y = [-2, 5, -8, 11, -14]
# z = [3, -6, -9, -12, 15]
ppp = [ x[i]+y[i]+z[i] for i in range(N)]
pmp = [ x[i]-y[i]+z[i] for i in range(N)]
ppm = [ x[i]+y[i]-z[i] for i in range(N)]
pmm = [ x[i]-y[i]-z[i] for i in range(N)]
mpp = [-x[i]+y[i]+z[i] for i in range(N)]
mpm = [-x[i]+y[i]-z[i] for i in range(N)]
mmp = [-x[i]-y[i]+z[i] for i in range(N)]
mmm = [-x[i]-y[i]-z[i] for i in range(N)]

MAX = 0
for lis in [ppp,pmp,ppm,pmm,mpp,mpm,mmp,mmm]:
	cur = functools.reduce(lambda x,y: x+y,filter(lambda t: t >= 0,lis))
	print(cur)
	if cur > MAX:
		MAX = cur
print(MAX)




Fixed submission:
import functools  # Python3 
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())

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

ppp = functools.reduce(lambda x,y: x+y,sorted([ x[i]+y[i]+z[i] for i in range(N)])[-M:])
pmp = functools.reduce(lambda x,y: x+y,sorted([ x[i]-y[i]+z[i] for i in range(N)])[-M:])
ppm = functools.reduce(lambda x,y: x+y,sorted([ x[i]+y[i]-z[i] for i in range(N)])[-M:])
pmm = functools.reduce(lambda x,y: x+y,sorted([ x[i]-y[i]-z[i] for i in range(N)])[-M:])
mpp = functools.reduce(lambda x,y: x+y,sorted([-x[i]+y[i]+z[i] for i in range(N)])[-M:])
mpm = functools.reduce(lambda x,y: x+y,sorted([-x[i]+y[i]-z[i] for i in range(N)])[-M:])
mmp = functools.reduce(lambda x,y: x+y,sorted([-x[i]-y[i]+z[i] for i in range(N)])[-M:])
mmm = functools.reduce(lambda x,y: x+y,sorted([-x[i]-y[i]-z[i] for i in range(N)])[-M:])

MAX = 0
for lis in [ppp,pmp,ppm,pmm,mpp,mpm,mmp,mmm]:
	if lis  > MAX:
		MAX = lis
print(MAX)