n,m = [int(i) for i in input().split()]



cakes = []

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

ranking2 = []



for i in range(n):

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



a = 0

for i in range(2):

    for j in range(2):

        for k in range(2):

            for x in range(n):

                kirei = cakes[x][0]

                oisii = cakes[x][1]

                ninki = cakes[x][2]

                if i ==1:

                    kirei = (-1)*kirei

                if j ==1:

                    oisii = (-1) * oisii

                if k==1:

                    ninki = (-1)*ninki

                sum = kirei + oisii + ninki

                ranking[a].append(sum)

            a += 1



for i in ranking:

    i = sorted(i)

    i = i[::-1]

    ranking2.append(i)



ans = 0



maxi = 0



for x in ranking2:

    ans = 0

    for i in range(m):

        ans += x[i]

    maxi = max(maxi,ans)

print(maxi)
n,m = [int(i) for i in input().split()]

ck = []

for i in range(n):

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



co1=co2=co3=-1



scores = []

maxi = 0

for i in range(2):

    co1 *= -1

    for j in range(2):

        co2 *= -1

        for k in range(2):

            co3*= -1

            scores = []

            score = 0

            for a,b,c in ck:

                scores.append(a*co1 + b*co2 + c*co3)

            scores.sort()

            for x in range(1,m+1):

                score += scores[-x]

            maxi = max(maxi,score)



print(maxi)
n, m = [int(i) for i in input().split()]
cakes = []
ranking = [[] for i in range(8)]
ranking2 = []
for i in range(n):
    cakes.append(list(map(int, input().split())))
a = 0
for i in range(2):
    for j in range(2):
        for k in range(2):
            for x in range(n):
                kirei = cakes[x][0]
                oisii = cakes[x][1]
                ninki = cakes[x][2]
                if i == 1:
                    kirei = (-1) * kirei
                if j == 1:
                    oisii = (-1) * oisii
                if k == 1:
                    ninki = (-1) * ninki
                sum = kirei + oisii + ninki
                ranking[a].append(sum)
            a += 1
for i in ranking:
    i = sorted(i)
    i = i[::-1]
    ranking2.append(i)
ans = 0
maxi = 0
for x in ranking2:
    ans = 0
    for i in range(m):
        ans += x[i]
    maxi = max(maxi, ans)
print(maxi)

n, m = [int(i) for i in input().split()]
ck = []
for i in range(n):
    ck.append(list(map(int, input().split())))
co1 = co2 = co3 = -1
scores = []
maxi = 0
for i in range(2):
    co1 *= -1
    for j in range(2):
        co2 *= -1
        for k in range(2):
            co3 *= -1
            scores = []
            score = 0
            for a, b, c in ck:
                scores.append(a * co1 + b * co2 + c * co3)
            scores.sort()
            for x in range(1, m + 1):
                score += scores[-x]
            maxi = max(maxi, score)
print(maxi)

-cakes = [] -ranking = [[] for i in range(8)] -ranking2 = [] +ck = [] -    cakes.append(list(map(int, input().split()))) -a = 0 +    ck.append(list(map(int, input().split()))) +co1 = co2 = co3 = -1 +scores = [] +maxi = 0 +    co1 *= -1 +        co2 *= -1 -            for x in range(n): -                kirei = cakes[x][0] -                oisii = cakes[x][1] -                ninki = cakes[x][2] -                if i == 1: -                    kirei = (-1) * kirei -                if j == 1: -                    oisii = (-1) * oisii -                if k == 1: -                    ninki = (-1) * ninki -                sum = kirei + oisii + ninki -                ranking[a].append(sum) -            a += 1 -for i in ranking: -    i = sorted(i) -    i = i[::-1] -    ranking2.append(i) -ans = 0 -maxi = 0 -for x in ranking2: -    ans = 0 -    for i in range(m): -        ans += x[i] -    maxi = max(maxi, ans) +            co3 *= -1 +            scores = [] +            score = 0 +            for a, b, c in ck: +                scores.append(a * co1 + b * co2 + c * co3) +            scores.sort() +            for x in range(1, m + 1): +                score += scores[-x] +            maxi = max(maxi, score)