from itertools import product



import numpy as np





def solve(string):

    n, m, *xyz = list(map(int, string.split()))

    xyz = [[x, y, z] for x, y, z in zip(xyz[::3], xyz[1::3], xyz[2::3])]

    xyz = np.asarray(xyz)

    ans = 0

    for i, j, k in product([-1, 1], repeat=3):

        tmp = xyz.copy()

        tmp[:, 0] = i * xyz[:, 0]

        tmp[:, 1] = j * xyz[:, 1]

        tmp[:, 2] = k * xyz[:, 2]

        base = sum(sorted(np.sum(tmp, axis=1), reverse=True)[:m])

        ans = max(ans, base)

    return str(ans)





if __name__ == '__main__':

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

    print((solve('{} {}\n'.format(n, m) + '\n'.join([eval(input()) for _ in range(n)]))))

from functools import partial

from itertools import islice





def take(n, iterable):

    return list(islice(iterable, n))





def chunked(iterable, n):

    return iter(partial(take, n, iter(iterable)), [])





def solve(s):

    n, m, *xyz = list(map(int, s.split()))

    ans = 0

    for sign_x in [1, -1]:

        for sign_y in [1, -1]:

            for sign_z in [1, -1]:

                ordered = sorted(

                    [x * sign_x + y * sign_y + z * sign_z for x, y, z in chunked(xyz, 3)],

                    reverse=True)

                ans = max(ans, sum(ordered[:m]))

    return ans





if __name__ == "__main__":

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

    print((solve('{} {}\n'.format(n, m) + '\n'.join([eval(input()) for _ in range(n)]))))

from itertools import product
import numpy as np


def solve(string):
    n, m, *xyz = list(map(int, string.split()))
    xyz = [[x, y, z] for x, y, z in zip(xyz[::3], xyz[1::3], xyz[2::3])]
    xyz = np.asarray(xyz)
    ans = 0
    for i, j, k in product([-1, 1], repeat=3):
        tmp = xyz.copy()
        tmp[:, 0] = i * xyz[:, 0]
        tmp[:, 1] = j * xyz[:, 1]
        tmp[:, 2] = k * xyz[:, 2]
        base = sum(sorted(np.sum(tmp, axis=1), reverse=True)[:m])
        ans = max(ans, base)
    return str(ans)


if __name__ == "__main__":
    n, m = list(map(int, input().split()))
    print(
        (solve("{} {}\n".format(n, m) + "\n".join([eval(input()) for _ in range(n)])))
    )

from functools import partial
from itertools import islice


def take(n, iterable):
    return list(islice(iterable, n))


def chunked(iterable, n):
    return iter(partial(take, n, iter(iterable)), [])


def solve(s):
    n, m, *xyz = list(map(int, s.split()))
    ans = 0
    for sign_x in [1, -1]:
        for sign_y in [1, -1]:
            for sign_z in [1, -1]:
                ordered = sorted(
                    [
                        x * sign_x + y * sign_y + z * sign_z
                        for x, y, z in chunked(xyz, 3)
                    ],
                    reverse=True,
                )
                ans = max(ans, sum(ordered[:m]))
    return ans


if __name__ == "__main__":
    n, m = list(map(int, input().split()))
    print(
        (solve("{} {}\n".format(n, m) + "\n".join([eval(input()) for _ in range(n)])))
    )

-from itertools import product -import numpy as np +from functools import partial +from itertools import islice -def solve(string): -    n, m, *xyz = list(map(int, string.split())) -    xyz = [[x, y, z] for x, y, z in zip(xyz[::3], xyz[1::3], xyz[2::3])] -    xyz = np.asarray(xyz) +def take(n, iterable): +    return list(islice(iterable, n)) + + +def chunked(iterable, n): +    return iter(partial(take, n, iter(iterable)), []) + + +def solve(s): +    n, m, *xyz = list(map(int, s.split())) -    for i, j, k in product([-1, 1], repeat=3): -        tmp = xyz.copy() -        tmp[:, 0] = i * xyz[:, 0] -        tmp[:, 1] = j * xyz[:, 1] -        tmp[:, 2] = k * xyz[:, 2] -        base = sum(sorted(np.sum(tmp, axis=1), reverse=True)[:m]) -        ans = max(ans, base) -    return str(ans) +    for sign_x in [1, -1]: +        for sign_y in [1, -1]: +            for sign_z in [1, -1]: +                ordered = sorted( +                    [ +                        x * sign_x + y * sign_y + z * sign_z +                        for x, y, z in chunked(xyz, 3) +                    ], +                    reverse=True, +                ) +                ans = max(ans, sum(ordered[:m])) +    return ans