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

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



if M==0:

    print((0))

    exit()



def dp(type):

    minimize_x = type&1

    minimize_y = (type>>1)&1

    minimize_z = (type>>2)&1

    dp = [0]

    for i,(x,y,z) in enumerate(src):

        if minimize_x: x *= -1

        if minimize_y: y *= -1

        if minimize_z: z *= -1

        v = x+y+z

        dp.append(dp[-1] + v)

        for j in reversed(list(range(i))):

            dp[j+1] = max(dp[j+1], dp[j] + v)

    return dp[M]



ans = 0

for i in range(8):

    ans = max(ans, dp(i))

print(ans)
import itertools

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

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



if M==0:

    print((0))

    exit()



ans = 0

for ptn in itertools.product([1,-1],repeat=3):

    results = []

    for row in src:

        results.append(sum([m*a for m,a in zip(ptn,row)]))

    ans = max(ans, sum(sorted(results)[-M:]))

print(ans)
N, M = list(map(int, input().split()))
src = [tuple(map(int, input().split())) for i in range(N)]
if M == 0:
    print((0))
    exit()


def dp(type):
    minimize_x = type & 1
    minimize_y = (type >> 1) & 1
    minimize_z = (type >> 2) & 1
    dp = [0]
    for i, (x, y, z) in enumerate(src):
        if minimize_x:
            x *= -1
        if minimize_y:
            y *= -1
        if minimize_z:
            z *= -1
        v = x + y + z
        dp.append(dp[-1] + v)
        for j in reversed(list(range(i))):
            dp[j + 1] = max(dp[j + 1], dp[j] + v)
    return dp[M]


ans = 0
for i in range(8):
    ans = max(ans, dp(i))
print(ans)

import itertools

N, M = list(map(int, input().split()))
src = [tuple(map(int, input().split())) for i in range(N)]
if M == 0:
    print((0))
    exit()
ans = 0
for ptn in itertools.product([1, -1], repeat=3):
    results = []
    for row in src:
        results.append(sum([m * a for m, a in zip(ptn, row)]))
    ans = max(ans, sum(sorted(results)[-M:]))
print(ans)

+import itertools + - - -def dp(type): -    minimize_x = type & 1 -    minimize_y = (type >> 1) & 1 -    minimize_z = (type >> 2) & 1 -    dp = [0] -    for i, (x, y, z) in enumerate(src): -        if minimize_x: -            x *= -1 -        if minimize_y: -            y *= -1 -        if minimize_z: -            z *= -1 -        v = x + y + z -        dp.append(dp[-1] + v) -        for j in reversed(list(range(i))): -            dp[j + 1] = max(dp[j + 1], dp[j] + v) -    return dp[M] - - -for i in range(8): -    ans = max(ans, dp(i)) +for ptn in itertools.product([1, -1], repeat=3): +    results = [] +    for row in src: +        results.append(sum([m * a for m, a in zip(ptn, row)])) +    ans = max(ans, sum(sorted(results)[-M:]))