from itertools import product

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

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



P = product((1, -1), repeat=3)



ans = 0

for x, y, z in P:

    tmp = []

    for a, b, c in C:

        tmp.append(a*x + b*y + c*z)

    tmp.sort(reverse=True)

    ans = max(ans, sum(tmp[:M]))



print(ans)

from itertools import product

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

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



ans = 0

for x, y, z in product([1, -1], repeat=3):

    tmp = []

    for a, b, c in cake:

        tmp.append(a*x + b*y + c*z)

    tmp.sort(reverse=True)

    ans = max(ans, sum(tmp[:M]))



print(ans)

from itertools import product

N, M = list(map(int, input().split()))
C = [list(map(int, input().split())) for i in range(N)]
P = product((1, -1), repeat=3)
ans = 0
for x, y, z in P:
    tmp = []
    for a, b, c in C:
        tmp.append(a * x + b * y + c * z)
    tmp.sort(reverse=True)
    ans = max(ans, sum(tmp[:M]))
print(ans)

from itertools import product

N, M = list(map(int, input().split()))
cake = [list(map(int, input().split())) for i in range(N)]
ans = 0
for x, y, z in product([1, -1], repeat=3):
    tmp = []
    for a, b, c in cake:
        tmp.append(a * x + b * y + c * z)
    tmp.sort(reverse=True)
    ans = max(ans, sum(tmp[:M]))
print(ans)

-C = [list(map(int, input().split())) for i in range(N)] -P = product((1, -1), repeat=3) +cake = [list(map(int, input().split())) for i in range(N)] -for x, y, z in P: +for x, y, z in product([1, -1], repeat=3): -    for a, b, c in C: +    for a, b, c in cake: