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

ls = []

for i in range(N):

    ls.append(list(map(int, input().split())))



answer = []

temp_ls = []



for j in [[1, 1, 1], [1, 1, -1], [1, -1, 1], [1, -1, -1], [-1, 1, 1],[-1, 1, -1], [-1, -1, 1], [-1, -1, -1]]:

    temp_ls = []

    for x in ls:

        temp = 0

        for i in range(3):

            temp += x[i]*j[i]

        temp_ls.append(temp)

    temp_ls.sort(reverse=True)

    temp_ans = 0

    for i in range(M):

        temp_ans += temp_ls[i]

    answer.append(temp_ans)

print((max(answer)))

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

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



ans = 0

for a in [1, -1]:

    for b in [1, -1]:

        for c in [1, -1]:

            s = []

            for x, y, z in xyz:

                s.append(a*x + b*y + c*z)

            s.sort(reverse=True)

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

print(ans)

N, M = list(map(int, input().split()))
ls = []
for i in range(N):
    ls.append(list(map(int, input().split())))
answer = []
temp_ls = []
for j in [
    [1, 1, 1],
    [1, 1, -1],
    [1, -1, 1],
    [1, -1, -1],
    [-1, 1, 1],
    [-1, 1, -1],
    [-1, -1, 1],
    [-1, -1, -1],
]:
    temp_ls = []
    for x in ls:
        temp = 0
        for i in range(3):
            temp += x[i] * j[i]
        temp_ls.append(temp)
    temp_ls.sort(reverse=True)
    temp_ans = 0
    for i in range(M):
        temp_ans += temp_ls[i]
    answer.append(temp_ans)
print((max(answer)))

N, M = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for a in [1, -1]:
    for b in [1, -1]:
        for c in [1, -1]:
            s = []
            for x, y, z in xyz:
                s.append(a * x + b * y + c * z)
            s.sort(reverse=True)
            ans = max(ans, sum(s[:M]))
print(ans)

-ls = [] -for i in range(N): -    ls.append(list(map(int, input().split()))) -answer = [] -temp_ls = [] -for j in [ -    [1, 1, 1], -    [1, 1, -1], -    [1, -1, 1], -    [1, -1, -1], -    [-1, 1, 1], -    [-1, 1, -1], -    [-1, -1, 1], -    [-1, -1, -1], -]: -    temp_ls = [] -    for x in ls: -        temp = 0 -        for i in range(3): -            temp += x[i] * j[i] -        temp_ls.append(temp) -    temp_ls.sort(reverse=True) -    temp_ans = 0 -    for i in range(M): -        temp_ans += temp_ls[i] -    answer.append(temp_ans) -print((max(answer))) +xyz = [list(map(int, input().split())) for _ in range(N)] +ans = 0 +for a in [1, -1]: +    for b in [1, -1]: +        for c in [1, -1]: +            s = [] +            for x, y, z in xyz: +                s.append(a * x + b * y + c * z) +            s.sort(reverse=True) +            ans = max(ans, sum(s[:M])) +print(ans)