import numpy as np

import itertools as it

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

xyz_l = []

for _ in range(n):

    x,y,z = list(map(int, input().split()))

    xyz_l.append((x,y,z))



xyz = np.array(xyz_l)



seed = ('+', '-')

pattern = list(it.product(seed, seed, seed))



ans = 0

for p in pattern:

    totals = []

    for (x,y,z) in xyz:

        t = 0

        if p[0] == '+':

            t += x

        else:

            t -= x

        if p[1] == '+':

            t += y

        else:

            t -= y

        if p[2] == '+':

            t += z

        else:

            t -= z

        totals.append(t)

    bs = list(reversed(sorted(totals)))

    cand = 0

    for i in range(m):

        cand += bs[i]

    ans = max(ans, cand)



print(ans)

import numpy as np

import itertools as it

import functools as ft



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

xyz_l = []

for _ in range(n):

    x,y,z = list(map(int, input().split()))

    xyz_l.append((x,y,z))



xyzs = np.array(xyz_l)



plus = lambda x, y : x + y

minus = lambda x, y : x - y



seed = (plus, minus)

pattern = np.array(list(it.product(seed,repeat=3)))



def map_pattern(p):

    reduce_func = lambda xs : ft.reduce((lambda t,k: k[0](t,k[1])), list(zip(p,xs)), 0)

    bs = np.array(list(reversed(sorted(map(reduce_func, xyzs)))))

    return sum(bs[:m])



ans = np.max(np.array(list(map(map_pattern, pattern))))



print(ans)

import numpy as np
import itertools as it

n, m = list(map(int, input().split()))
xyz_l = []
for _ in range(n):
    x, y, z = list(map(int, input().split()))
    xyz_l.append((x, y, z))
xyz = np.array(xyz_l)
seed = ("+", "-")
pattern = list(it.product(seed, seed, seed))
ans = 0
for p in pattern:
    totals = []
    for (x, y, z) in xyz:
        t = 0
        if p[0] == "+":
            t += x
        else:
            t -= x
        if p[1] == "+":
            t += y
        else:
            t -= y
        if p[2] == "+":
            t += z
        else:
            t -= z
        totals.append(t)
    bs = list(reversed(sorted(totals)))
    cand = 0
    for i in range(m):
        cand += bs[i]
    ans = max(ans, cand)
print(ans)

import numpy as np
import itertools as it
import functools as ft

n, m = list(map(int, input().split()))
xyz_l = []
for _ in range(n):
    x, y, z = list(map(int, input().split()))
    xyz_l.append((x, y, z))
xyzs = np.array(xyz_l)
plus = lambda x, y: x + y
minus = lambda x, y: x - y
seed = (plus, minus)
pattern = np.array(list(it.product(seed, repeat=3)))


def map_pattern(p):
    reduce_func = lambda xs: ft.reduce(
        (lambda t, k: k[0](t, k[1])), list(zip(p, xs)), 0
    )
    bs = np.array(list(reversed(sorted(map(reduce_func, xyzs)))))
    return sum(bs[:m])


ans = np.max(np.array(list(map(map_pattern, pattern))))
print(ans)

+import functools as ft -xyz = np.array(xyz_l) -seed = ("+", "-") -pattern = list(it.product(seed, seed, seed)) -ans = 0 -for p in pattern: -    totals = [] -    for (x, y, z) in xyz: -        t = 0 -        if p[0] == "+": -            t += x -        else: -            t -= x -        if p[1] == "+": -            t += y -        else: -            t -= y -        if p[2] == "+": -            t += z -        else: -            t -= z -        totals.append(t) -    bs = list(reversed(sorted(totals))) -    cand = 0 -    for i in range(m): -        cand += bs[i] -    ans = max(ans, cand) +xyzs = np.array(xyz_l) +plus = lambda x, y: x + y +minus = lambda x, y: x - y +seed = (plus, minus) +pattern = np.array(list(it.product(seed, repeat=3))) + + +def map_pattern(p): +    reduce_func = lambda xs: ft.reduce( +        (lambda t, k: k[0](t, k[1])), list(zip(p, xs)), 0 +    ) +    bs = np.array(list(reversed(sorted(map(reduce_func, xyzs))))) +    return sum(bs[:m]) + + +ans = np.max(np.array(list(map(map_pattern, pattern))))