import itertools

import heapq

n,m = [int(i) for i in input().split()]

a = [[int(i) for i in input().split()] for j in range(n)]

ans = 0

c = [0,1]

for l,j,k in itertools.product(c,repeat=3):

    ans = max(ans,sum(heapq.nlargest(m,([a[i][0]*(-1)**l+a[i][1]*(-1)**j+a[i][2]*(-1)**k for i in range(n)]))))

print(ans)
from itertools import product as p

n,m = [int(i) for i in input().split()]

a = [[int(i) for i in input().split()] for j in range(n)]

c = [1,-1]

ans = 0

for l,j,k in p(c,repeat=3):

    ans = max(ans,sum(sorted([a[i][0]*l+a[i][1]*j+a[i][2]*k for i in range(n)])[n-m:])) 

print(ans)
import itertools
import heapq

n, m = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]
ans = 0
c = [0, 1]
for l, j, k in itertools.product(c, repeat=3):
    ans = max(
        ans,
        sum(
            heapq.nlargest(
                m,
                (
                    [
                        a[i][0] * (-1) ** l + a[i][1] * (-1) ** j + a[i][2] * (-1) ** k
                        for i in range(n)
                    ]
                ),
            )
        ),
    )
print(ans)

from itertools import product as p

n, m = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]
c = [1, -1]
ans = 0
for l, j, k in p(c, repeat=3):
    ans = max(
        ans,
        sum(
            sorted([a[i][0] * l + a[i][1] * j + a[i][2] * k for i in range(n)])[n - m :]
        ),
    )
print(ans)

-import itertools -import heapq +from itertools import product as p +c = [1, -1] -c = [0, 1] -for l, j, k in itertools.product(c, repeat=3): +for l, j, k in p(c, repeat=3): -            heapq.nlargest( -                m, -                ( -                    [ -                        a[i][0] * (-1) ** l + a[i][1] * (-1) ** j + a[i][2] * (-1) ** k -                        for i in range(n) -                    ] -                ), -            ) +            sorted([a[i][0] * l + a[i][1] * j + a[i][2] * k for i in range(n)])[n - m :]