import itertools

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

x=[0 for i in range(N)]

y=[0 for i in range(N)]

z=[0 for i in range(N)]

for i in range(N):

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

w=[[0 for i in range(N)] for i in range(8)]

S=list(itertools.product([-1,1],repeat=3))

def num(inp):

    res=0

    for i in range(3):

        res+=2**i*(inp[i]+1)//2

    return res

for sg in S:

    for i in range(N):

        w[num(sg)][i]=x[i]*sg[0]+y[i]*sg[1]+z[i]*sg[2]

tmp=[0 for i in range(8)]

for sg in S:

    w[num(sg)].sort(reverse=True)

    for i in range(M):

        tmp[num(sg)]+=w[num(sg)][i]

print((max(tmp)))
import itertools

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

x=[0 for i in range(N)]

y=[0 for i in range(N)]

z=[0 for i in range(N)]

for i in range(N):

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

S=list(itertools.product([-1,1],repeat=3))

def num(seq):

    res=0

    for i in range(3):

        if seq[i]==1:

            res+=2**i

    return res

ans=0

for seq in S:

    A=[seq[0]*x[i]+seq[1]*y[i]+seq[2]*z[i] for i in range(N)]

    A.sort(reverse=True)

    tmp=0

    for i in range(M):

        tmp+=A[i]

    if tmp>ans:

        ans=tmp

print(ans)

import itertools

N, M = list(map(int, input().split()))
x = [0 for i in range(N)]
y = [0 for i in range(N)]
z = [0 for i in range(N)]
for i in range(N):
    x[i], y[i], z[i] = list(map(int, input().split()))
w = [[0 for i in range(N)] for i in range(8)]
S = list(itertools.product([-1, 1], repeat=3))


def num(inp):
    res = 0
    for i in range(3):
        res += 2**i * (inp[i] + 1) // 2
    return res


for sg in S:
    for i in range(N):
        w[num(sg)][i] = x[i] * sg[0] + y[i] * sg[1] + z[i] * sg[2]
tmp = [0 for i in range(8)]
for sg in S:
    w[num(sg)].sort(reverse=True)
    for i in range(M):
        tmp[num(sg)] += w[num(sg)][i]
print((max(tmp)))

import itertools

N, M = list(map(int, input().split()))
x = [0 for i in range(N)]
y = [0 for i in range(N)]
z = [0 for i in range(N)]
for i in range(N):
    x[i], y[i], z[i] = list(map(int, input().split()))
S = list(itertools.product([-1, 1], repeat=3))


def num(seq):
    res = 0
    for i in range(3):
        if seq[i] == 1:
            res += 2**i
    return res


ans = 0
for seq in S:
    A = [seq[0] * x[i] + seq[1] * y[i] + seq[2] * z[i] for i in range(N)]
    A.sort(reverse=True)
    tmp = 0
    for i in range(M):
        tmp += A[i]
    if tmp > ans:
        ans = tmp
print(ans)

-w = [[0 for i in range(N)] for i in range(8)] -def num(inp): +def num(seq): -        res += 2**i * (inp[i] + 1) // 2 +        if seq[i] == 1: +            res += 2**i -for sg in S: -    for i in range(N): -        w[num(sg)][i] = x[i] * sg[0] + y[i] * sg[1] + z[i] * sg[2] -tmp = [0 for i in range(8)] -for sg in S: -    w[num(sg)].sort(reverse=True) +ans = 0 +for seq in S: +    A = [seq[0] * x[i] + seq[1] * y[i] + seq[2] * z[i] for i in range(N)] +    A.sort(reverse=True) +    tmp = 0 -        tmp[num(sg)] += w[num(sg)][i] -print((max(tmp))) +        tmp += A[i] +    if tmp > ans: +        ans = tmp +print(ans)