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

box=list(list(map(int,input().split())) for i in range(n))

ans = 0

for i in (1,-1):

    for j in (1,-1):

        for k in (1,-1):

            cost=list(i*x+j*y+z*k for x,y,z in box)

            cost.sort(reverse=True)

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

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

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



ans=0

for i in (-1,1):

    for j in (-1,1):

        for k in (-1,1):

            cost=list(i*x+j*y+z*k for x,y,z in XYZ)

            cost.sort(reverse=True)

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

print(ans)
n, m = list(map(int, input().split()))
box = list(list(map(int, input().split())) for i in range(n))
ans = 0
for i in (1, -1):
    for j in (1, -1):
        for k in (1, -1):
            cost = list(i * x + j * y + z * k for x, y, z in box)
            cost.sort(reverse=True)
            ans = max(ans, sum(cost[:m]))
print(ans)

n, m = list(map(int, input().split()))
XYZ = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in (-1, 1):
    for j in (-1, 1):
        for k in (-1, 1):
            cost = list(i * x + j * y + z * k for x, y, z in XYZ)
            cost.sort(reverse=True)
            ans = max(ans, sum(cost[:m]))
print(ans)

-box = list(list(map(int, input().split())) for i in range(n)) +XYZ = [list(map(int, input().split())) for _ in range(n)] -for i in (1, -1): -    for j in (1, -1): -        for k in (1, -1): -            cost = list(i * x + j * y + z * k for x, y, z in box) +for i in (-1, 1): +    for j in (-1, 1): +        for k in (-1, 1): +            cost = list(i * x + j * y + z * k for x, y, z in XYZ)