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

XYZs = [list(map(int, input().split())) for _ in range(N)]



ans = 0

for op in range(1 << 3):

    lst = []

    for xyz in XYZs:

        v = 0

        for j in range(3):

            v += xyz[j] * ((-1) ** ((op >> j) & 1))

        lst.append(v)

    ans = max(ans, sum(sorted(lst, reverse=True)[:M]))



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

XYZs = [tuple(map(int, input().split())) for _ in range(N)]



ans = 0

for i in range(1 << 3):

    signs = []

    for j in range(3):

        if i >> j & 1:

            signs.append(1)

        else:

            signs.append(-1)

    t = []

    for xyz in XYZs:

        x, y, z = xyz

        t.append(x * signs[0] + y * signs[1] + z * signs[2])

    ans = max(ans, sum(sorted(t, reverse=True)[:M]))

print(ans)
N, M = list(map(int, input().split()))
XYZs = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for op in range(1 << 3):
    lst = []
    for xyz in XYZs:
        v = 0
        for j in range(3):
            v += xyz[j] * ((-1) ** ((op >> j) & 1))
        lst.append(v)
    ans = max(ans, sum(sorted(lst, reverse=True)[:M]))
print(ans)

N, M = list(map(int, input().split()))
XYZs = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(1 << 3):
    signs = []
    for j in range(3):
        if i >> j & 1:
            signs.append(1)
        else:
            signs.append(-1)
    t = []
    for xyz in XYZs:
        x, y, z = xyz
        t.append(x * signs[0] + y * signs[1] + z * signs[2])
    ans = max(ans, sum(sorted(t, reverse=True)[:M]))
print(ans)

-XYZs = [list(map(int, input().split())) for _ in range(N)] +XYZs = [tuple(map(int, input().split())) for _ in range(N)] -for op in range(1 << 3): -    lst = [] +for i in range(1 << 3): +    signs = [] +    for j in range(3): +        if i >> j & 1: +            signs.append(1) +        else: +            signs.append(-1) +    t = [] -        v = 0 -        for j in range(3): -            v += xyz[j] * ((-1) ** ((op >> j) & 1)) -        lst.append(v) -    ans = max(ans, sum(sorted(lst, reverse=True)[:M])) +        x, y, z = xyz +        t.append(x * signs[0] + y * signs[1] + z * signs[2]) +    ans = max(ans, sum(sorted(t, reverse=True)[:M]))