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

cakes=[]

for i in range(N):

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

  cakes.append([x,y,z])

if M==0:

  print((0))

  quit()

score=[0]*8

score[0]=sum(sorted([c[0]+c[1]+c[2] for c in cakes])[-M:])

score[1]=sum(sorted([c[0]+c[1]-c[2] for c in cakes])[-M:])

score[2]=sum(sorted([c[0]-c[1]+c[2] for c in cakes])[-M:])

score[3]=sum(sorted([c[0]-c[1]-c[2] for c in cakes])[-M:])

score[4]=sum(sorted([-c[0]+c[1]+c[2] for c in cakes])[-M:])

score[5]=sum(sorted([-c[0]+c[1]-c[2] for c in cakes])[-M:])

score[6]=sum(sorted([-c[0]-c[1]+c[2] for c in cakes])[-M:])

score[7]=sum(sorted([-c[0]-c[1]-c[2] for c in cakes])[-M:])

print((max(score)))

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

cakes=[]

for i in range(N):

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

  cakes.append([x,y,z])

if M==0:

  print((0))

  quit()

score=[0]*8

s=sorted([c[0]+c[1]+c[2] for c in cakes])

score[0]=sum(s[-M:])

score[1]=-sum(s[:M])

s=sorted([c[0]+c[1]-c[2] for c in cakes])

score[2]=sum(s[-M:])

score[3]=-sum(s[:M])

s=sorted([c[0]-c[1]+c[2] for c in cakes])

score[4]=sum(s[-M:])

score[5]=-sum(s[:M])

s=sorted([c[0]-c[1]-c[2] for c in cakes])

score[6]=sum(s[-M:])

score[7]=-sum(s[:M])

print((max(score)))

quit()

N, M = list(map(int, input().split()))
cakes = []
for i in range(N):
    x, y, z = list(map(int, input().split()))
    cakes.append([x, y, z])
if M == 0:
    print((0))
    quit()
score = [0] * 8
score[0] = sum(sorted([c[0] + c[1] + c[2] for c in cakes])[-M:])
score[1] = sum(sorted([c[0] + c[1] - c[2] for c in cakes])[-M:])
score[2] = sum(sorted([c[0] - c[1] + c[2] for c in cakes])[-M:])
score[3] = sum(sorted([c[0] - c[1] - c[2] for c in cakes])[-M:])
score[4] = sum(sorted([-c[0] + c[1] + c[2] for c in cakes])[-M:])
score[5] = sum(sorted([-c[0] + c[1] - c[2] for c in cakes])[-M:])
score[6] = sum(sorted([-c[0] - c[1] + c[2] for c in cakes])[-M:])
score[7] = sum(sorted([-c[0] - c[1] - c[2] for c in cakes])[-M:])
print((max(score)))

N, M = list(map(int, input().split()))
cakes = []
for i in range(N):
    x, y, z = list(map(int, input().split()))
    cakes.append([x, y, z])
if M == 0:
    print((0))
    quit()
score = [0] * 8
s = sorted([c[0] + c[1] + c[2] for c in cakes])
score[0] = sum(s[-M:])
score[1] = -sum(s[:M])
s = sorted([c[0] + c[1] - c[2] for c in cakes])
score[2] = sum(s[-M:])
score[3] = -sum(s[:M])
s = sorted([c[0] - c[1] + c[2] for c in cakes])
score[4] = sum(s[-M:])
score[5] = -sum(s[:M])
s = sorted([c[0] - c[1] - c[2] for c in cakes])
score[6] = sum(s[-M:])
score[7] = -sum(s[:M])
print((max(score)))
quit()

-score[0] = sum(sorted([c[0] + c[1] + c[2] for c in cakes])[-M:]) -score[1] = sum(sorted([c[0] + c[1] - c[2] for c in cakes])[-M:]) -score[2] = sum(sorted([c[0] - c[1] + c[2] for c in cakes])[-M:]) -score[3] = sum(sorted([c[0] - c[1] - c[2] for c in cakes])[-M:]) -score[4] = sum(sorted([-c[0] + c[1] + c[2] for c in cakes])[-M:]) -score[5] = sum(sorted([-c[0] + c[1] - c[2] for c in cakes])[-M:]) -score[6] = sum(sorted([-c[0] - c[1] + c[2] for c in cakes])[-M:]) -score[7] = sum(sorted([-c[0] - c[1] - c[2] for c in cakes])[-M:]) +s = sorted([c[0] + c[1] + c[2] for c in cakes]) +score[0] = sum(s[-M:]) +score[1] = -sum(s[:M]) +s = sorted([c[0] + c[1] - c[2] for c in cakes]) +score[2] = sum(s[-M:]) +score[3] = -sum(s[:M]) +s = sorted([c[0] - c[1] + c[2] for c in cakes]) +score[4] = sum(s[-M:]) +score[5] = -sum(s[:M]) +s = sorted([c[0] - c[1] - c[2] for c in cakes]) +score[6] = sum(s[-M:]) +score[7] = -sum(s[:M]) +quit()