import numpy as np



def calc(op1, op2, op3):

    # op... True...+, False...-

    op1_flag = op2_flag = op3_flag = 1

    if not op1:

        op1_flag = -1

    if not op2:

        op2_flag = -1

    if not op3:

        op3_flag = -1

    return xyz[:, 0]*op1_flag + xyz[:, 1]*op2_flag + xyz[:, 2]*op3_flag



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

xyz = np.array([list(map(int, input().split())) for i in range(N)])

ans = 0

ops = [[1,1,1], [1,1,0], [1,0,1], [1,0,0], [0,1,1], [0,1,0], [0,0,1], [0,0,0]]

for op1, op2, op3 in ops:

    table = np.sort(calc(op1, op2, op3))[::-1]

    ans = max(ans, np.sum(table[:M]))



print(ans)
calc = lambda op1, op2, op3, xyz: op1*xyz[0] + op2*xyz[1] + op3*xyz[2]



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

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

ans = 0

ops = [[1,1,1], [1,1,-1], [1,-1,1], [1,-1,-1], [-1,1,1], [-1,1,-1], [-1,-1,1], [-1,-1,-1]]



for op1, op2, op3 in ops:

    nums = sorted([calc(op1, op2, op3, n) for n in xyz], reverse=True)

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

print(ans)
import numpy as np


def calc(op1, op2, op3):
    # op... True...+, False...-
    op1_flag = op2_flag = op3_flag = 1
    if not op1:
        op1_flag = -1
    if not op2:
        op2_flag = -1
    if not op3:
        op3_flag = -1
    return xyz[:, 0] * op1_flag + xyz[:, 1] * op2_flag + xyz[:, 2] * op3_flag


N, M = list(map(int, input().split()))
xyz = np.array([list(map(int, input().split())) for i in range(N)])
ans = 0
ops = [
    [1, 1, 1],
    [1, 1, 0],
    [1, 0, 1],
    [1, 0, 0],
    [0, 1, 1],
    [0, 1, 0],
    [0, 0, 1],
    [0, 0, 0],
]
for op1, op2, op3 in ops:
    table = np.sort(calc(op1, op2, op3))[::-1]
    ans = max(ans, np.sum(table[:M]))
print(ans)

calc = lambda op1, op2, op3, xyz: op1 * xyz[0] + op2 * xyz[1] + op3 * xyz[2]
N, M = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for i in range(N)]
ans = 0
ops = [
    [1, 1, 1],
    [1, 1, -1],
    [1, -1, 1],
    [1, -1, -1],
    [-1, 1, 1],
    [-1, 1, -1],
    [-1, -1, 1],
    [-1, -1, -1],
]
for op1, op2, op3 in ops:
    nums = sorted([calc(op1, op2, op3, n) for n in xyz], reverse=True)
    ans = max(ans, sum(nums[:M]))
print(ans)

-import numpy as np - - -def calc(op1, op2, op3): -    # op... True...+, False...- -    op1_flag = op2_flag = op3_flag = 1 -    if not op1: -        op1_flag = -1 -    if not op2: -        op2_flag = -1 -    if not op3: -        op3_flag = -1 -    return xyz[:, 0] * op1_flag + xyz[:, 1] * op2_flag + xyz[:, 2] * op3_flag - - +calc = lambda op1, op2, op3, xyz: op1 * xyz[0] + op2 * xyz[1] + op3 * xyz[2] -xyz = np.array([list(map(int, input().split())) for i in range(N)]) +xyz = [list(map(int, input().split())) for i in range(N)] -    [1, 1, 0], -    [1, 0, 1], -    [1, 0, 0], -    [0, 1, 1], -    [0, 1, 0], -    [0, 0, 1], -    [0, 0, 0], +    [1, 1, -1], +    [1, -1, 1], +    [1, -1, -1], +    [-1, 1, 1], +    [-1, 1, -1], +    [-1, -1, 1], +    [-1, -1, -1], -    table = np.sort(calc(op1, op2, op3))[::-1] -    ans = max(ans, np.sum(table[:M])) +    nums = sorted([calc(op1, op2, op3, n) for n in xyz], reverse=True) +    ans = max(ans, sum(nums[:M]))