n, m = list(map(int, input().split()))

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

ans = 0

op = [-1,1]

for i in range(2):

    for j in range(2):

        for k in range(2):

            sx, sy, sz = op[i], op[j], op[k]

            dp = [-float("inf")]*(m+1)

            dp[0] = 0

            for l, (x, y, z) in enumerate(v):

                x *= sx

                y *= sy

                z *= sz

                score = x+y+z

                for h in range(min(m,l+1),0,-1):

                    dp[h] = max(dp[h], dp[h-1]+score)

            ans = max(ans, dp[-1])

print(ans)
import numpy as np

n, m = list(map(int, input().split()))

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

ans = 0

op = [-1,1]

for i in range(2):

    for j in range(2):

        for k in range(2):

            sx, sy, sz = op[i], op[j], op[k]

            dp = np.full(m+1, -np.inf, dtype=np.float64)

            dp[0] = 0

            for x, y, z in v:

                x *= sx

                y *= sy

                z *= sz

                dp[1:] = np.maximum(dp[1:], dp[:-1]+x+y+z)

            ans = max(ans, dp[-1])

print((int(ans)))
n, m = list(map(int, input().split()))
v = [list(map(int, input().split())) for i in range(n)]
ans = 0
op = [-1, 1]
for i in range(2):
    for j in range(2):
        for k in range(2):
            sx, sy, sz = op[i], op[j], op[k]
            dp = [-float("inf")] * (m + 1)
            dp[0] = 0
            for l, (x, y, z) in enumerate(v):
                x *= sx
                y *= sy
                z *= sz
                score = x + y + z
                for h in range(min(m, l + 1), 0, -1):
                    dp[h] = max(dp[h], dp[h - 1] + score)
            ans = max(ans, dp[-1])
print(ans)

import numpy as np

n, m = list(map(int, input().split()))
v = [list(map(int, input().split())) for i in range(n)]
ans = 0
op = [-1, 1]
for i in range(2):
    for j in range(2):
        for k in range(2):
            sx, sy, sz = op[i], op[j], op[k]
            dp = np.full(m + 1, -np.inf, dtype=np.float64)
            dp[0] = 0
            for x, y, z in v:
                x *= sx
                y *= sy
                z *= sz
                dp[1:] = np.maximum(dp[1:], dp[:-1] + x + y + z)
            ans = max(ans, dp[-1])
print((int(ans)))

+import numpy as np + -            dp = [-float("inf")] * (m + 1) +            dp = np.full(m + 1, -np.inf, dtype=np.float64) -            for l, (x, y, z) in enumerate(v): +            for x, y, z in v: -                score = x + y + z -                for h in range(min(m, l + 1), 0, -1): -                    dp[h] = max(dp[h], dp[h - 1] + score) +                dp[1:] = np.maximum(dp[1:], dp[:-1] + x + y + z) -print(ans) +print((int(ans)))