Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
X=list()
Y=list()
Z=list()
for i in range(n):
    x,y,z=map(int,input().split())
    X.append(x)
    Y.append(y)
    Z.append(z)
A=list()
B=list()
C=list()
D=list()
for i in range(n):
    A.append(X[i]+Y[i]+Z[i])
    B.append(-X[i]+Y[i]+Z[i])
    C.append(X[i]-Y[i]+Z[i])
    D.append(X[i]+Y[i]-Z[i])
import functools
A.sort()
B.sort()
C.sort()
D.sort()
x1=functools.reduce(lambda x,y:x+y,[A[i] for i in range(m)])
x2=functools.reduce(lambda x,y:x+y,[A[-i] for i in range(1,m+1)])
y1=functools.reduce(lambda x,y:x+y,[B[i] for i in range(m)])
y2=functools.reduce(lambda x,y:x+y,[B[-i] for i in range(1,m+1)])
z1=functools.reduce(lambda x,y:x+y,[C[i] for i in range(m)])
z2=functools.reduce(lambda x,y:x+y,[C[-i] for i in range(1,m+1)])
w1=functools.reduce(lambda x,y:x+y,[D[i] for i in range(m)])
w2=functools.reduce(lambda x,y:x+y,[D[-i] for i in range(1,m+1)])
print(max(abs(x1),abs(x2),abs(y1),abs(y2),abs(z1),abs(z2),abs(w1),abs(w2)))



Fixed submission:
n,m=map(int,input().split())
X=list()
Y=list()
Z=list()
for i in range(n):
    x,y,z=map(int,input().split())
    X.append(x)
    Y.append(y)
    Z.append(z)
A=list()
B=list()
C=list()
D=list()
for i in range(n):
    A.append(X[i]+Y[i]+Z[i])
    B.append(-X[i]+Y[i]+Z[i])
    C.append(X[i]-Y[i]+Z[i])
    D.append(X[i]+Y[i]-Z[i])
import functools
A.sort()
B.sort()
C.sort()
D.sort()
if m==0:
    print(0)
else:
    x1=functools.reduce(lambda x,y:x+y,[A[i] for i in range(m)])
    x2=functools.reduce(lambda x,y:x+y,[A[-i] for i in range(1,m+1)])
    y1=functools.reduce(lambda x,y:x+y,[B[i] for i in range(m)])
    y2=functools.reduce(lambda x,y:x+y,[B[-i] for i in range(1,m+1)])
    z1=functools.reduce(lambda x,y:x+y,[C[i] for i in range(m)])
    z2=functools.reduce(lambda x,y:x+y,[C[-i] for i in range(1,m+1)])
    w1=functools.reduce(lambda x,y:x+y,[D[i] for i in range(m)])
    w2=functools.reduce(lambda x,y:x+y,[D[-i] for i in range(1,m+1)])
    print(max(abs(x1),abs(x2),abs(y1),abs(y2),abs(z1),abs(z2),abs(w1),abs(w2)))

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
X=list()
Y=list()
Z=list()
for i in range(n):
    x,y,z=map(int,input().split())
    X.append(x)
    Y.append(y)
    Z.append(z)
A=[]
B=[]
C=[]
D=[]
for i in range(n):
    A.append(X[i]+Y[i]+Z[i])
    B.append(-X[i]+Y[i]+Z[i])
    C.append(X[i]-Y[i]+Z[i])
    D.append(X[i]+Y[i]-Z[i])
import functools
A.sort()
B.sort()
C.sort()
D.sort()
x1=functools.reduce(lambda x,y:x+y,[A[i] for i in range(m)])
x2=functools.reduce(lambda x,y:x+y,[A[-i] for i in range(1,m+1)])
y1=functools.reduce(lambda x,y:x+y,[B[i] for i in range(m)])
y2=functools.reduce(lambda x,y:x+y,[B[-i] for i in range(1,m+1)])
z1=functools.reduce(lambda x,y:x+y,[C[i] for i in range(m)])
z2=functools.reduce(lambda x,y:x+y,[C[-i] for i in range(1,m+1)])
w1=functools.reduce(lambda x,y:x+y,[D[i] for i in range(m)])
w2=functools.reduce(lambda x,y:x+y,[D[-i] for i in range(1,m+1)])
print(max(abs(x1),abs(x2),abs(y1),abs(y2),abs(z1),abs(z2),abs(w1),abs(w2)))

Fixed submission:
n,m=map(int,input().split())
X=list()
Y=list()
Z=list()
for i in range(n):
    x,y,z=map(int,input().split())
    X.append(x)
    Y.append(y)
    Z.append(z)
A=list()
B=list()
C=list()
D=list()
for i in range(n):
    A.append(X[i]+Y[i]+Z[i])
    B.append(-X[i]+Y[i]+Z[i])
    C.append(X[i]-Y[i]+Z[i])
    D.append(X[i]+Y[i]-Z[i])
import functools
A.sort()
B.sort()
C.sort()
D.sort()
if m==0:
    print(0)
else:
    x1=functools.reduce(lambda x,y:x+y,[A[i] for i in range(m)])
    x2=functools.reduce(lambda x,y:x+y,[A[-i] for i in range(1,m+1)])
    y1=functools.reduce(lambda x,y:x+y,[B[i] for i in range(m)])
    y2=functools.reduce(lambda x,y:x+y,[B[-i] for i in range(1,m+1)])
    z1=functools.reduce(lambda x,y:x+y,[C[i] for i in range(m)])
    z2=functools.reduce(lambda x,y:x+y,[C[-i] for i in range(1,m+1)])
    w1=functools.reduce(lambda x,y:x+y,[D[i] for i in range(m)])
    w2=functools.reduce(lambda x,y:x+y,[D[-i] for i in range(1,m+1)])
    print(max(abs(x1),abs(x2),abs(y1),abs(y2),abs(z1),abs(z2),abs(w1),abs(w2)))