import numpy as np

N,M = list(map(int,input().split()))

x = []

y = []

z = []

for i in range(N):

    a,b,c = list(map(int,input().split()))

    x.append(a)

    y.append(b)

    z.append(c)

x = np.array(x)

y = np.array(y)

z = np.array(z)

ppp = x+y+z

ppn = x+y-z

pnp = x-y+z

pnn = x-y-z

npp = -x+y+z

npn = -x+y-z

nnp = -x-y+z

nnn = -x-y-z

score=[]

score.append(sum(sorted(list(ppp))[::-1][:M]))

score.append(sum(sorted(list(ppn))[::-1][:M]))

score.append(sum(sorted(list(pnp))[::-1][:M]))

score.append(sum(sorted(list(pnn))[::-1][:M]))

score.append(sum(sorted(list(npp))[::-1][:M]))

score.append(sum(sorted(list(npn))[::-1][:M]))

score.append(sum(sorted(list(nnp))[::-1][:M]))

score.append(sum(sorted(list(nnn))[::-1][:M]))

print((max(score)))

N,M=list(map(int,input().split()))

X = [[] for i in range(8)]

for i in range(N):

    x,y,z=list(map(int,input().split()))

    for i in range(8):

        X[i].append(int(2*((i%2)-1/2))*x + int(2*(((i//2)%2)-1/2))*y + int(2*(((i//4)%2)-1/2))*z)

ans=0

for i in range(8):

    X[i].sort()

    X[i]=X[i][::-1]

    ans=max(sum(X[i][:M]),ans)

    

print(ans)
import numpy as np

N, M = list(map(int, input().split()))
x = []
y = []
z = []
for i in range(N):
    a, b, c = list(map(int, input().split()))
    x.append(a)
    y.append(b)
    z.append(c)
x = np.array(x)
y = np.array(y)
z = np.array(z)
ppp = x + y + z
ppn = x + y - z
pnp = x - y + z
pnn = x - y - z
npp = -x + y + z
npn = -x + y - z
nnp = -x - y + z
nnn = -x - y - z
score = []
score.append(sum(sorted(list(ppp))[::-1][:M]))
score.append(sum(sorted(list(ppn))[::-1][:M]))
score.append(sum(sorted(list(pnp))[::-1][:M]))
score.append(sum(sorted(list(pnn))[::-1][:M]))
score.append(sum(sorted(list(npp))[::-1][:M]))
score.append(sum(sorted(list(npn))[::-1][:M]))
score.append(sum(sorted(list(nnp))[::-1][:M]))
score.append(sum(sorted(list(nnn))[::-1][:M]))
print((max(score)))

N, M = list(map(int, input().split()))
X = [[] for i in range(8)]
for i in range(N):
    x, y, z = list(map(int, input().split()))
    for i in range(8):
        X[i].append(
            int(2 * ((i % 2) - 1 / 2)) * x
            + int(2 * (((i // 2) % 2) - 1 / 2)) * y
            + int(2 * (((i // 4) % 2) - 1 / 2)) * z
        )
ans = 0
for i in range(8):
    X[i].sort()
    X[i] = X[i][::-1]
    ans = max(sum(X[i][:M]), ans)
print(ans)

-import numpy as np - -x = [] -y = [] -z = [] +X = [[] for i in range(8)] -    a, b, c = list(map(int, input().split())) -    x.append(a) -    y.append(b) -    z.append(c) -x = np.array(x) -y = np.array(y) -z = np.array(z) -ppp = x + y + z -ppn = x + y - z -pnp = x - y + z -pnn = x - y - z -npp = -x + y + z -npn = -x + y - z -nnp = -x - y + z -nnn = -x - y - z -score = [] -score.append(sum(sorted(list(ppp))[::-1][:M])) -score.append(sum(sorted(list(ppn))[::-1][:M])) -score.append(sum(sorted(list(pnp))[::-1][:M])) -score.append(sum(sorted(list(pnn))[::-1][:M])) -score.append(sum(sorted(list(npp))[::-1][:M])) -score.append(sum(sorted(list(npn))[::-1][:M])) -score.append(sum(sorted(list(nnp))[::-1][:M])) -score.append(sum(sorted(list(nnn))[::-1][:M])) -print((max(score))) +    x, y, z = list(map(int, input().split())) +    for i in range(8): +        X[i].append( +            int(2 * ((i % 2) - 1 / 2)) * x +            + int(2 * (((i // 2) % 2) - 1 / 2)) * y +            + int(2 * (((i // 4) % 2) - 1 / 2)) * z +        ) +ans = 0 +for i in range(8): +    X[i].sort() +    X[i] = X[i][::-1] +    ans = max(sum(X[i][:M]), ans) +print(ans)