# https://atcoder.jp/contests/abc100/tasks/abc100_d



from itertools import product



N, M, *XYZ = list(map(int, open(0).read().split()))



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



A = [[] for _ in range(8)]

for x, y, z in zip(*[iter(XYZ)] * 3):

    for i, (a, b, c) in enumerate(P):

        A[i].append(a * x + b * y + c * z)



cand = []

for i in range(8):

    A[i].sort(reverse=True)

    cand.append(sum(A[i][:M]))



print((max(cand)))

N, M, *XYZ = list(map(int, open(0).read().split()))



A = [[] for _ in range(8)]

for x, y, z in zip(*[iter(XYZ)] * 3):

    A[0].append(sum((x, y, z)))

    A[1].append(sum((x, y, -z)))

    A[2].append(sum((x, -y, z)))

    A[3].append(sum((x, -y, -z)))

    A[4].append(sum((-x, y, z)))

    A[5].append(sum((-x, y, -z)))

    A[6].append(sum((-x, -y, z)))

    A[7].append(sum((-x, -y, -z)))



cand = []

for i in range(8):

    A[i].sort(reverse=True)

    cand.append(sum(A[i][:M]))



print((max(cand)))

# https://atcoder.jp/contests/abc100/tasks/abc100_d
from itertools import product

N, M, *XYZ = list(map(int, open(0).read().split()))
P = tuple(product((1, -1), repeat=3))
A = [[] for _ in range(8)]
for x, y, z in zip(*[iter(XYZ)] * 3):
    for i, (a, b, c) in enumerate(P):
        A[i].append(a * x + b * y + c * z)
cand = []
for i in range(8):
    A[i].sort(reverse=True)
    cand.append(sum(A[i][:M]))
print((max(cand)))

N, M, *XYZ = list(map(int, open(0).read().split()))
A = [[] for _ in range(8)]
for x, y, z in zip(*[iter(XYZ)] * 3):
    A[0].append(sum((x, y, z)))
    A[1].append(sum((x, y, -z)))
    A[2].append(sum((x, -y, z)))
    A[3].append(sum((x, -y, -z)))
    A[4].append(sum((-x, y, z)))
    A[5].append(sum((-x, y, -z)))
    A[6].append(sum((-x, -y, z)))
    A[7].append(sum((-x, -y, -z)))
cand = []
for i in range(8):
    A[i].sort(reverse=True)
    cand.append(sum(A[i][:M]))
print((max(cand)))

-# https://atcoder.jp/contests/abc100/tasks/abc100_d -from itertools import product - -P = tuple(product((1, -1), repeat=3)) -    for i, (a, b, c) in enumerate(P): -        A[i].append(a * x + b * y + c * z) +    A[0].append(sum((x, y, z))) +    A[1].append(sum((x, y, -z))) +    A[2].append(sum((x, -y, z))) +    A[3].append(sum((x, -y, -z))) +    A[4].append(sum((-x, y, z))) +    A[5].append(sum((-x, y, -z))) +    A[6].append(sum((-x, -y, z))) +    A[7].append(sum((-x, -y, -z)))