import functools

[N, M] = [int(x) for x in input().split()]

XYZ = []

for i in range(N):

  XYZ.append([int(x) for x in input().split()])

result = 0

for x in range(-1, 2, 2):

  for y in range(-1, 2, 2):

    for z in range(-1, 2, 2):

      contribute = [x, y, z]

      score = [functools.reduce(lambda a, b: a + b, [xyz[i] * contribute[i] for i in range(3)]) for xyz in XYZ]

      score.sort(reverse=True)

      S = functools.reduce(lambda a, b: a + b, score[:M]) if M else 0

      result = max(result, S)

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

Cakes = [[] for i in range(N)]

for i in range(N):

  Cakes[i] = [int(x) for x in input().split()]

ans = 0

for s in range(8):

  sx = 1 if s % 2 else -1

  sy = 1 if s // 2 % 2 else -1

  sz = 1 if s // 4 % 2 else -1

  ans = max(sum(sorted([sx * x + sy * y + sz * z for x, y, z in Cakes], reverse=True)[:M]), ans)

print(ans)
import functools

[N, M] = [int(x) for x in input().split()]
XYZ = []
for i in range(N):
    XYZ.append([int(x) for x in input().split()])
result = 0
for x in range(-1, 2, 2):
    for y in range(-1, 2, 2):
        for z in range(-1, 2, 2):
            contribute = [x, y, z]
            score = [
                functools.reduce(
                    lambda a, b: a + b, [xyz[i] * contribute[i] for i in range(3)]
                )
                for xyz in XYZ
            ]
            score.sort(reverse=True)
            S = functools.reduce(lambda a, b: a + b, score[:M]) if M else 0
            result = max(result, S)
print(result)

N, M = list(map(int, input().split()))
Cakes = [[] for i in range(N)]
for i in range(N):
    Cakes[i] = [int(x) for x in input().split()]
ans = 0
for s in range(8):
    sx = 1 if s % 2 else -1
    sy = 1 if s // 2 % 2 else -1
    sz = 1 if s // 4 % 2 else -1
    ans = max(
        sum(sorted([sx * x + sy * y + sz * z for x, y, z in Cakes], reverse=True)[:M]),
        ans,
    )
print(ans)

-import functools - -[N, M] = [int(x) for x in input().split()] -XYZ = [] +N, M = list(map(int, input().split())) +Cakes = [[] for i in range(N)] -    XYZ.append([int(x) for x in input().split()]) -result = 0 -for x in range(-1, 2, 2): -    for y in range(-1, 2, 2): -        for z in range(-1, 2, 2): -            contribute = [x, y, z] -            score = [ -                functools.reduce( -                    lambda a, b: a + b, [xyz[i] * contribute[i] for i in range(3)] -                ) -                for xyz in XYZ -            ] -            score.sort(reverse=True) -            S = functools.reduce(lambda a, b: a + b, score[:M]) if M else 0 -            result = max(result, S) -print(result) +    Cakes[i] = [int(x) for x in input().split()] +ans = 0 +for s in range(8): +    sx = 1 if s % 2 else -1 +    sy = 1 if s // 2 % 2 else -1 +    sz = 1 if s // 4 % 2 else -1 +    ans = max( +        sum(sorted([sx * x + sy * y + sz * z for x, y, z in Cakes], reverse=True)[:M]), +        ans, +    ) +print(ans)