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

xs,ys,zs = [], [], []

"""

sum000 +++

sum001 ++-

sum010 +-+

sum011 +--

sum100 -++

sum101 -+-

sum110 --+

sum111 ---

"""





sum000, sum001, sum010,sum011 = [], [], [], []

sum100, sum101, sum110,sum111 = [], [], [], []

sums = [[] for i in range(8)]

for i in range(N):

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

    sums[0].append(x+y+z)

    sums[1].append(x+y-z)

    sums[2].append(x-y+z)

    sums[3].append(x-y-z)

    sums[4].append(-x+y+z)

    sums[5].append(-x+y-z)

    sums[6].append(-x-y+z)

    sums[7].append(-x-y-z)



ans = 0

for s in sums:

    s1 = sorted(s,reverse=False)

    s2 = sorted(s,reverse=False)

    x = max(abs(sum(s1[:M])),abs(sum(s2[:M])))

    ans = max(ans,x)

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



"""

 xyz

0+++

1++-

2+-+

3+--

4-++

5-+-

6--+

7---



"""

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





for i in range(N):

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

    dp[0][i] = x+y+z

    dp[1][i] = x+y-z

    dp[2][i] = x-y+z

    dp[3][i] = x-y-z

    dp[4][i] = -x+y+z

    dp[5][i] = -x+y-z

    dp[6][i] = -x-y+z

    dp[7][i] = -x-y-z



ans = 0

for i in range(8):

    sums = sorted(dp[i], reverse=True)

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

print(ans)
N, M = list(map(int, input().split()))
xs, ys, zs = [], [], []
"""
sum000 +++
sum001 ++-
sum010 +-+
sum011 +--
sum100 -++
sum101 -+-
sum110 --+
sum111 ---
"""
sum000, sum001, sum010, sum011 = [], [], [], []
sum100, sum101, sum110, sum111 = [], [], [], []
sums = [[] for i in range(8)]
for i in range(N):
    x, y, z = list(map(int, input().split()))
    sums[0].append(x + y + z)
    sums[1].append(x + y - z)
    sums[2].append(x - y + z)
    sums[3].append(x - y - z)
    sums[4].append(-x + y + z)
    sums[5].append(-x + y - z)
    sums[6].append(-x - y + z)
    sums[7].append(-x - y - z)
ans = 0
for s in sums:
    s1 = sorted(s, reverse=False)
    s2 = sorted(s, reverse=False)
    x = max(abs(sum(s1[:M])), abs(sum(s2[:M])))
    ans = max(ans, x)
print(ans)

N, M = list(map(int, input().split()))
"""
 xyz
0+++
1++-
2+-+
3+--
4-++
5-+-
6--+
7---
"""
dp = [[0] * N for i in range(8)]
for i in range(N):
    x, y, z = list(map(int, input().split()))
    dp[0][i] = x + y + z
    dp[1][i] = x + y - z
    dp[2][i] = x - y + z
    dp[3][i] = x - y - z
    dp[4][i] = -x + y + z
    dp[5][i] = -x + y - z
    dp[6][i] = -x - y + z
    dp[7][i] = -x - y - z
ans = 0
for i in range(8):
    sums = sorted(dp[i], reverse=True)
    ans = max(sum(sums[:M]), ans)
print(ans)

-xs, ys, zs = [], [], [] -sum001 ++- -sum010 +-+ -sum011 +-- -sum100 -++ -sum101 -+- -sum110 --+ + xyz +1++- +2+-+ +3+-- +4-++ +5-+- +6--+ -sum000, sum001, sum010, sum011 = [], [], [], [] -sum100, sum101, sum110, sum111 = [], [], [], [] -sums = [[] for i in range(8)] +dp = [[0] * N for i in range(8)] -    sums[0].append(x + y + z) -    sums[1].append(x + y - z) -    sums[2].append(x - y + z) -    sums[3].append(x - y - z) -    sums[4].append(-x + y + z) -    sums[5].append(-x + y - z) -    sums[6].append(-x - y + z) -    sums[7].append(-x - y - z) +    dp[0][i] = x + y + z +    dp[1][i] = x + y - z +    dp[2][i] = x - y + z +    dp[3][i] = x - y - z +    dp[4][i] = -x + y + z +    dp[5][i] = -x + y - z +    dp[6][i] = -x - y + z +    dp[7][i] = -x - y - z -for s in sums: -    s1 = sorted(s, reverse=False) -    s2 = sorted(s, reverse=False) -    x = max(abs(sum(s1[:M])), abs(sum(s2[:M]))) -    ans = max(ans, x) +for i in range(8): +    sums = sorted(dp[i], reverse=True) +    ans = max(sum(sums[:M]), ans)