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

cakes = []

for i in range(N):

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



ans = 0



for i in range(8):

    values = []

    for cake in cakes:

        value = 0

        for j in range(3):

            if (i >> j) % 2 == 1:

                value -= cake[j]

            else:

                value += cake[j]

        values.append(value)

    values.sort()

    values = values[::-1]

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



print(ans)

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

cakes = []

for i in range(N):

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



ans = 0



values = []

for x,y,z in cakes:

    values.append(x+y+z)

values.sort()

values = values[::-1]

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



values = []

for x,y,z in cakes:

    values.append(x+y-z)

values.sort()

values = values[::-1]

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





values = []

for x,y,z in cakes:

    values.append(x-y+z)

values.sort()

values = values[::-1]

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





values = []

for x,y,z in cakes:

    values.append(x-y-z)

values.sort()

values = values[::-1]

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





values = []

for x,y,z in cakes:

    values.append(-x+y+z)

values.sort()

values = values[::-1]

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





values = []

for x,y,z in cakes:

    values.append(-x+y-z)

values.sort()

values = values[::-1]

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







values = []

for x,y,z in cakes:

    values.append(-x-y+z)

values.sort()

values = values[::-1]

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





values = []

for x,y,z in cakes:

    values.append(-x-y-z)

values.sort()

values = values[::-1]

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





print(ans)

N, M = list(map(int, input().split()))
cakes = []
for i in range(N):
    cakes.append(list(map(int, input().split())))
ans = 0
for i in range(8):
    values = []
    for cake in cakes:
        value = 0
        for j in range(3):
            if (i >> j) % 2 == 1:
                value -= cake[j]
            else:
                value += cake[j]
        values.append(value)
    values.sort()
    values = values[::-1]
    ans = max(ans, sum(values[:M]))
print(ans)

N, M = list(map(int, input().split()))
cakes = []
for i in range(N):
    cakes.append(list(map(int, input().split())))
ans = 0
values = []
for x, y, z in cakes:
    values.append(x + y + z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))
values = []
for x, y, z in cakes:
    values.append(x + y - z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))
values = []
for x, y, z in cakes:
    values.append(x - y + z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))
values = []
for x, y, z in cakes:
    values.append(x - y - z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))
values = []
for x, y, z in cakes:
    values.append(-x + y + z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))
values = []
for x, y, z in cakes:
    values.append(-x + y - z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))
values = []
for x, y, z in cakes:
    values.append(-x - y + z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))
values = []
for x, y, z in cakes:
    values.append(-x - y - z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))
print(ans)

-for i in range(8): -    values = [] -    for cake in cakes: -        value = 0 -        for j in range(3): -            if (i >> j) % 2 == 1: -                value -= cake[j] -            else: -                value += cake[j] -        values.append(value) -    values.sort() -    values = values[::-1] -    ans = max(ans, sum(values[:M])) +values = [] +for x, y, z in cakes: +    values.append(x + y + z) +values.sort() +values = values[::-1] +ans = max(ans, sum(values[:M])) +values = [] +for x, y, z in cakes: +    values.append(x + y - z) +values.sort() +values = values[::-1] +ans = max(ans, sum(values[:M])) +values = [] +for x, y, z in cakes: +    values.append(x - y + z) +values.sort() +values = values[::-1] +ans = max(ans, sum(values[:M])) +values = [] +for x, y, z in cakes: +    values.append(x - y - z) +values.sort() +values = values[::-1] +ans = max(ans, sum(values[:M])) +values = [] +for x, y, z in cakes: +    values.append(-x + y + z) +values.sort() +values = values[::-1] +ans = max(ans, sum(values[:M])) +values = [] +for x, y, z in cakes: +    values.append(-x + y - z) +values.sort() +values = values[::-1] +ans = max(ans, sum(values[:M])) +values = [] +for x, y, z in cakes: +    values.append(-x - y + z) +values.sort() +values = values[::-1] +ans = max(ans, sum(values[:M])) +values = [] +for x, y, z in cakes: +    values.append(-x - y - z) +values.sort() +values = values[::-1] +ans = max(ans, sum(values[:M]))