import numpy as np

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

a = np.zeros((8,N))

for i in range(N):

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

    j=0

    for j1 in range(2):

        for j2 in range(2):

            for j3 in range(2):

                a[j][i] = (-1)**j1*x+(-1)**j2*y+(-1)**j3*z

                j += 1

ans = 0

for j in range(8):

    ref = sum(sorted(a[j])[-M:])

    ans = max(ans,ref)

if M == 0:

    ans = 0

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

xyz = [list(map(int,input().split())) for _ in range(N)]



ans = 0

for n in range(8):

    n = bin(n)[2:]

    n = (3-len(n))*'0' + n

    n = [1-2*int(s) for s in n]

    S = [0]*N

    for i in range(N):

        S[i] = n[0]*xyz[i][0]+n[1]*xyz[i][1]+n[2]*xyz[i][2]

    S.sort()

    ans = max(ans,sum(S[N-M:]))



print(ans)
import numpy as np

N, M = list(map(int, input().split()))
a = np.zeros((8, N))
for i in range(N):
    x, y, z = list(map(int, input().split()))
    j = 0
    for j1 in range(2):
        for j2 in range(2):
            for j3 in range(2):
                a[j][i] = (-1) ** j1 * x + (-1) ** j2 * y + (-1) ** j3 * z
                j += 1
ans = 0
for j in range(8):
    ref = sum(sorted(a[j])[-M:])
    ans = max(ans, ref)
if M == 0:
    ans = 0
print((int(ans)))

N, M = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for n in range(8):
    n = bin(n)[2:]
    n = (3 - len(n)) * "0" + n
    n = [1 - 2 * int(s) for s in n]
    S = [0] * N
    for i in range(N):
        S[i] = n[0] * xyz[i][0] + n[1] * xyz[i][1] + n[2] * xyz[i][2]
    S.sort()
    ans = max(ans, sum(S[N - M :]))
print(ans)

-import numpy as np - -a = np.zeros((8, N)) -for i in range(N): -    x, y, z = list(map(int, input().split())) -    j = 0 -    for j1 in range(2): -        for j2 in range(2): -            for j3 in range(2): -                a[j][i] = (-1) ** j1 * x + (-1) ** j2 * y + (-1) ** j3 * z -                j += 1 +xyz = [list(map(int, input().split())) for _ in range(N)] -for j in range(8): -    ref = sum(sorted(a[j])[-M:]) -    ans = max(ans, ref) -if M == 0: -    ans = 0 -print((int(ans))) +for n in range(8): +    n = bin(n)[2:] +    n = (3 - len(n)) * "0" + n +    n = [1 - 2 * int(s) for s in n] +    S = [0] * N +    for i in range(N): +        S[i] = n[0] * xyz[i][0] + n[1] * xyz[i][1] + n[2] * xyz[i][2] +    S.sort() +    ans = max(ans, sum(S[N - M :])) +print(ans)