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

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



ans = 0

for i in range(8):

    sign = [0,0,0]

    for j in range(3):

        sign[j] = (i>>j & 1)

    cake_i = []

    for k in range(N):

        s = 0

        for j in range(3):

            s += cake[k][j]*(1-2*sign[j])

        cake_i.append(s)

    cake_i.sort(reverse = True)

    ans = max(ans,sum(cake_i[:M]))

    

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

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



res = 0



for i in range(8):

    D = [0 for _ in range(N)]

    for j in range(N):

        x, y, z = C[j]

        if (i >> 0) & 1:

            D[j] += x

        else:

            D[j] -= x

        if (i >> 1) & 1:

            D[j] += y

        else:

            D[j] -= y

        if (i >> 2) & 1:

            D[j] += z

        else:

            D[j] -= z

    D.sort(reverse=True)

    res = max(res, sum(D[:M]))



print(res)
N, M = list(map(int, input().split()))
cake = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(8):
    sign = [0, 0, 0]
    for j in range(3):
        sign[j] = i >> j & 1
    cake_i = []
    for k in range(N):
        s = 0
        for j in range(3):
            s += cake[k][j] * (1 - 2 * sign[j])
        cake_i.append(s)
    cake_i.sort(reverse=True)
    ans = max(ans, sum(cake_i[:M]))
print(ans)

N, M = list(map(int, input().split()))
C = [tuple(map(int, input().split())) for _ in range(N)]
res = 0
for i in range(8):
    D = [0 for _ in range(N)]
    for j in range(N):
        x, y, z = C[j]
        if (i >> 0) & 1:
            D[j] += x
        else:
            D[j] -= x
        if (i >> 1) & 1:
            D[j] += y
        else:
            D[j] -= y
        if (i >> 2) & 1:
            D[j] += z
        else:
            D[j] -= z
    D.sort(reverse=True)
    res = max(res, sum(D[:M]))
print(res)

-cake = [list(map(int, input().split())) for _ in range(N)] -ans = 0 +C = [tuple(map(int, input().split())) for _ in range(N)] +res = 0 -    sign = [0, 0, 0] -    for j in range(3): -        sign[j] = i >> j & 1 -    cake_i = [] -    for k in range(N): -        s = 0 -        for j in range(3): -            s += cake[k][j] * (1 - 2 * sign[j]) -        cake_i.append(s) -    cake_i.sort(reverse=True) -    ans = max(ans, sum(cake_i[:M])) -print(ans) +    D = [0 for _ in range(N)] +    for j in range(N): +        x, y, z = C[j] +        if (i >> 0) & 1: +            D[j] += x +        else: +            D[j] -= x +        if (i >> 1) & 1: +            D[j] += y +        else: +            D[j] -= y +        if (i >> 2) & 1: +            D[j] += z +        else: +            D[j] -= z +    D.sort(reverse=True) +    res = max(res, sum(D[:M])) +print(res)