import itertools

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

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

note = []

for x,y,z in info:

    X = [x,-x]; Y = [y,-y]; Z = [z,-z]

    tmp = []

    for c in itertools.product(X,Y,Z):

        tmp.append(sum(c))

    note.append(tmp)



ans = -float('inf')

for j in range(8):

    res = []

    for i in range(N):

        res.append(note[i][j])

    res = sorted(res,reverse=True)

    value = sum(res[:M])

    if value > ans:

        ans = value

print(ans)
import itertools

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

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

ans = -float('inf')

for i,j,k in itertools.product([1,-1],repeat=3):

    tmp = []

    for x,y,z in info:

        value = x*i + y*j + z*k

        tmp.append(value)

    tmp.sort(reverse=True)

    res = sum(tmp[:M])

    if res > ans:

        ans = res

print(ans)
import itertools

N, M = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(N)]
note = []
for x, y, z in info:
    X = [x, -x]
    Y = [y, -y]
    Z = [z, -z]
    tmp = []
    for c in itertools.product(X, Y, Z):
        tmp.append(sum(c))
    note.append(tmp)
ans = -float("inf")
for j in range(8):
    res = []
    for i in range(N):
        res.append(note[i][j])
    res = sorted(res, reverse=True)
    value = sum(res[:M])
    if value > ans:
        ans = value
print(ans)

import itertools

N, M = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(N)]
ans = -float("inf")
for i, j, k in itertools.product([1, -1], repeat=3):
    tmp = []
    for x, y, z in info:
        value = x * i + y * j + z * k
        tmp.append(value)
    tmp.sort(reverse=True)
    res = sum(tmp[:M])
    if res > ans:
        ans = res
print(ans)

-note = [] -for x, y, z in info: -    X = [x, -x] -    Y = [y, -y] -    Z = [z, -z] +ans = -float("inf") +for i, j, k in itertools.product([1, -1], repeat=3): -    for c in itertools.product(X, Y, Z): -        tmp.append(sum(c)) -    note.append(tmp) -ans = -float("inf") -for j in range(8): -    res = [] -    for i in range(N): -        res.append(note[i][j]) -    res = sorted(res, reverse=True) -    value = sum(res[:M]) -    if value > ans: -        ans = value +    for x, y, z in info: +        value = x * i + y * j + z * k +        tmp.append(value) +    tmp.sort(reverse=True) +    res = sum(tmp[:M]) +    if res > ans: +        ans = res