CodeEff/ECCO huggingface dataset:
# Original solution
from itertools import combinations
from sys import stdin, stdout
input = lambda: stdin.readline().rstrip()
println = stdout.write

def main():
    N, M = list(map(int, input().split()))
    XYZ = [tuple(map(int, input().split())) for _ in [0] * N]

    ans = -float('inf')
    for cake in combinations(XYZ, M):
        x, y, z = 0, 0, 0
        for i, j, k in cake:
            x += i; y += j; z += k
        for xm in (x, -x):
            for ym in (y, -y):
                for zm in (z, -z):
                    ans = max(ans, xm + ym + zm)
    print(ans)

main()


# Optimized solution
from itertools import combinations, product
from sys import stdin, stdout
input = lambda: stdin.readline().rstrip()
println = stdout.write

def main():
    N, M = list(map(int, input().split()))
    XYZ = [tuple(map(int, input().split())) for _ in [0] * N]

    cake = [0] * N
    ans = -float('inf')
    for kx, ky, kz in product((1, -1), repeat=3):
        for i, (x, y, z) in enumerate(XYZ):
            cake[i] = sum((x * kx, y * ky, z * kz))
        cake.sort(reverse=1)
        ans = max(ans, sum(cake[:M]))
    print(ans)

main()
# Original solution
import sys
input = sys.stdin.readline

N, M = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for bit in range(1 << 3):
    dp = [-float('inf')] * (M+1)
    dp[0] = 0
    for i in range(N):
        for j in range(M)[::-1]:
            if dp[j] != -float('inf'):
                score = 0
                for k in range(3):
                    score += xyz[i][k] * (-1)**((bit >> k) & 1)
                dp[j+1] = max(dp[j+1], dp[j] + score)
    ans = max(ans, dp[M])
print(ans)


# Optimized solution
N, M = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for bit in range(1 << 3):
    scores = [0] * N
    for i in range(N):
        for j in range(3):
            scores[i] += xyz[i][j] * (-1)**((bit >> j) & 1)
    scores.sort(reverse=True)
    ans = max(ans, sum(scores[:M]))
print(ans)
# Original solution
N,M=list(map(int,input().split()))
xyz=[]
for i in range(N):
    xyz.append(list(map(int,input().split())))
coefs=[[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1]
       ,[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]]
ans=[]

for ix,iy,iz in coefs:
    xyz_ = [sum([ix*l[0],iy*l[1],iz*l[2]]) for l in xyz]
    dp=[[0]*(M+1) for i in range(N+1)]
    for i in range(N):
        dp[i+1][0] = dp[i][0]
        for j in range(1,M+1):
            dp[i+1][j] = max(dp[i][j-1]+xyz_[i],dp[i][j])
    ans.append(dp[N][M])
print((max(ans)))

# Optimized solution
N,M=list(map(int,input().split()))
xyz=[]
for i in range(N):
    xyz.append(list(map(int,input().split())))
coefs=[[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1]
       ,[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]]
ans=[]

for ix,iy,iz in coefs:
    xyz_ = [sum([ix*l[0],iy*l[1],iz*l[2]]) for l in xyz]
    ans.append(sum(sorted(xyz_,reverse=True)[:M]))
print((max(ans)))
# Original solution
N, M = list(map(int, input().split()))
cake = [list(map(int, input().split())) for _ in range(N)]

dp = [[[0] * 8 for _ in range(M + 1)] for _ in range(N + 1)]

for i in range(1, N + 1):
    x, y, z = cake[i - 1]
    for j in range(1, M + 1):
        for msk in range(8):
            mx = x * (1 - 2 * (msk >> 2 & 1))
            my = y * (1 - 2 * (msk >> 1 & 1))
            mz = z * (1 - 2 * (msk >> 0 & 1))
            dp[i][j][msk] = max(dp[i - 1][j][msk],
                                dp[i - 1][j - 1][msk] + mx + my + mz)

print((max(dp[N][M][i] for i in range(8))))

# Optimized solution
N, M = list(map(int, input().split()))
cake = [list(map(int, input().split())) for _ in range(N)]

INF = 10 ** 18
dp = [[[-INF] * 8 for _ in range(M + 1)] for _ in range(N + 1)]
for i in range(N + 1):
    for msk in range(8):
        dp[i][0][msk] = 0

for i in range(1, N + 1):
    x, y, z = cake[i - 1]
    for j in range(1, M + 1):
        for msk in range(8):
            mx = x * (1 - 2 * (msk >> 2 & 1))
            my = y * (1 - 2 * (msk >> 1 & 1))
            mz = z * (1 - 2 * (msk >> 0 & 1))
            dp[i][j][msk] = max(dp[i - 1][j][msk],
                                dp[i - 1][j - 1][msk] + mx + my + mz)

print((max(dp[N][M][i] for i in range(8))))
# Original solution
N, M = list(map(int, input().split()))
cake = [list(map(int, input().split())) for _ in range(N)]

INF = 10 ** 18
dp = [[[-INF] * 8 for _ in range(M + 1)] for _ in range(N + 1)]
for i in range(N + 1):
    for msk in range(8):
        dp[i][0][msk] = 0

for i in range(1, N + 1):
    x, y, z = cake[i - 1]
    for j in range(1, M + 1):
        for msk in range(8):
            mx = x * (1 - 2 * (msk >> 2 & 1))
            my = y * (1 - 2 * (msk >> 1 & 1))
            mz = z * (1 - 2 * (msk >> 0 & 1))
            dp[i][j][msk] = max(dp[i - 1][j][msk],
                                dp[i - 1][j - 1][msk] + mx + my + mz)

print((max(dp[N][M][i] for i in range(8))))

# Optimized solution
N, M = list(map(int, input().split()))
cake = [list(map(int, input().split())) for _ in range(N)]

ans = [[] for _ in range(8)]
for x, y, z in cake:
    for msk in range(8):
        mx = x * (1 - 2 * (msk >> 2 & 1))
        my = y * (1 - 2 * (msk >> 1 & 1))
        mz = z * (1 - 2 * (msk >> 0 & 1))
        ans[msk].append(mx + my + mz)

print((max(sum(sorted(x, reverse=True)[:M]) for x in ans)))
# Original solution
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)

# Optimized solution
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)
# Original solution
import itertools as it

def f(c):
    x = abs(sum([i[0] for i in c]))
    y = abs(sum([i[1] for i in c]))
    z = abs(sum([i[2] for i in c]))
    return x + y + z

N, M = tuple(map(int, input().split()))
v = [[int(x) for x in input().split()] for j in range(N)]
c = list(it.combinations(v, M))
print((max(f(x) for x in c)))

# Optimized solution
N, M = tuple(map(int, input().split()))
v = [[int(x) for x in input().split()] for j in range(N)]
v2 = [[v[i][0]*p + v[i][1]*q + v[i][2]*r for i in range(N)] for p in [1, -1] for q in [1, -1] for r in [1, -1]]
v3 = [sorted(v2[i], reverse=True) for i in range(8)]
m = 0
for i in range(8):
    n = sum(v3[i][:M])
    if n > m:
        m = n

print(m)
# Original solution
# -*- coding: utf-8 -*-
# AtCoder Beginner Contest


if __name__ == '__main__':
    from itertools import product
    from heapq import nlargest

    n, m = list(map(int, input().split()))
    xyz = [list(map(int, input().split())) for i in range(n)]
    ans = 0

    # See:
    # https://beta.atcoder.jp/contests/abc100/submissions/2691346
    for a, b, c in product((-1, 1), repeat=3):
        summed_xyz = [0 for _ in range(n)]
        i = 0

        for x, y, z in xyz:
            summed_xyz[i] = (x * a) + (y * b) + (z * c)
            i += 1

        ans = max(ans, sum(nlargest(m, summed_xyz)))

    print(ans)


# Optimized solution
# -*- coding: utf-8 -*-


def main():
    from itertools import product

    n, m = list(map(int, input().split()))
    xyz = [list(map(int, input().split())) for _ in range(n)]
    ans = 0

    for op1, op2, op3 in list(product([1, -1], repeat=3)):
        tmp = [[0, 0, 0]] * n

        for index, value in enumerate(xyz):
            tmp[index] = sum([op1 * value[0], op2 * value[1], op3 * value[2]])

        camdidates = sorted(tmp, reverse=True)
        ans = max(ans, sum(camdidates[:m]))

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
L=lambda:list(map(int,input().split()));r=range;n,m=L();k=[L()for _ in r(n)];print((max(-sum(sorted([-sum([j[i]*(int(bin(s)[2:].zfill(3)[i])*2-1)for i in r(3)])for j in k])[:m])for s in r(8))))

# Optimized solution
n,m=list(map(int,input().split()))
xyz=[list(map(int,input().split()))for _ in range(n)]
def f(fx,fy,fz):
  t=[]
  for x,y,z in xyz:t.append(x*fx+y*fy+z*fz)
  t.sort(reverse=1)
  return sum(t[:m])
ans=0
ans=max(ans,f(1,1,1))
ans=max(ans,f(1,1,-1))
ans=max(ans,f(1,-1,1))
ans=max(ans,f(1,-1,-1))
ans=max(ans,f(-1,1,1))
ans=max(ans,f(-1,1,-1))
ans=max(ans,f(-1,-1,1))
ans=max(ans,f(-1,-1,-1))
print(ans)
# Original solution
N,M=list(map(int,input().split()))
dp_ppp=[-1000000]*(N+1)
dp_mpp=[-1000000]*(N+1)
dp_pmp=[-1000000]*(N+1)
dp_ppm=[-1000000]*(N+1)
dp_mmp=[-1000000]*(N+1)
dp_mpm=[-1000000]*(N+1)
dp_pmm=[-1000000]*(N+1)
dp_mmm=[-1000000]*(N+1)
dp_ppp[0]=0
dp_mpp[0]=0
dp_pmp[0]=0
dp_ppm[0]=0
dp_mmp[0]=0
dp_mpm[0]=0
dp_pmm[0]=0
dp_mmm[0]=0
for i in range(N):
  x,y,z=list(map(int,input().split()))
  for j in range(min(i+1,M),0,-1):
    if dp_ppp[j-1]>=0:
      dp_ppp[j]=max([dp_ppp[j],dp_ppp[j-1]+x+y+z])
    if dp_mpp[j-1]>=0:
      dp_mpp[j]=max([dp_mpp[j],dp_mpp[j-1]-x+y+z])
    if dp_pmp[j-1]>=0:
      dp_pmp[j]=max([dp_pmp[j],dp_pmp[j-1]+x-y+z])
    if dp_ppm[j-1]>=0:
      dp_ppm[j]=max([dp_ppm[j],dp_ppm[j-1]+x+y-z])
    if dp_mmp[j-1]>=0:
      dp_mmp[j]=max([dp_mmp[j],dp_mmp[j-1]-x-y+z])
    if dp_mpm[j-1]>=0:
      dp_mpm[j]=max([dp_mpm[j],dp_mpm[j-1]-x+y-z])
    if dp_pmm[j-1]>=0:
      dp_pmm[j]=max([dp_pmm[j],dp_pmm[j-1]+x-y-z])
    if dp_mmm[j-1]>=0:
      dp_mmm[j]=max([dp_mmm[j],dp_mmm[j-1]-x-y-z])

ans=max([dp_ppp[M],dp_mpp[M],dp_pmp[M],dp_ppm[M],dp_mmp[M],dp_mpm[M],dp_pmm[M],dp_mmm[M]])
if ans>0:
  print(ans)
else:
  print((0))

# Optimized solution
import sys
input=sys.stdin.readline
N,M=list(map(int,input().split()))
dp_ppp=[]
dp_mpp=[]
dp_pmp=[]
dp_ppm=[]
dp_mmp=[]
dp_mpm=[]
dp_pmm=[]
dp_mmm=[]
for i in range(N):
  x,y,z=list(map(int,input().split()))
  dp_ppp.append(x+y+z)
  dp_mpp.append(-x+y+z)
  dp_pmp.append(x-y+z)
  dp_ppm.append(x+y-z)
  dp_mmp.append(-x-y+z)
  dp_mpm.append(-x+y-z)
  dp_pmm.append(x-y-z)
  dp_mmm.append(-x-y-z)
dp_ppp.sort(key=lambda x:-x)
dp_mpp.sort(key=lambda x:-x)
dp_pmp.sort(key=lambda x:-x)
dp_ppm.sort(key=lambda x:-x)
dp_mmp.sort(key=lambda x:-x)
dp_mpm.sort(key=lambda x:-x)
dp_pmm.sort(key=lambda x:-x)
dp_mmm.sort(key=lambda x:-x)
ppp=sum(dp_ppp[0:M])
mpp=sum(dp_mpp[0:M])
pmp=sum(dp_pmp[0:M])
ppm=sum(dp_ppm[0:M])
mmp=sum(dp_mmp[0:M])
mpm=sum(dp_mpm[0:M])
pmm=sum(dp_pmm[0:M])
mmm=sum(dp_mmm[0:M])
ans=max([ppp,mpp,pmp,ppm,mmp,mpm,pmm,mmm])
print(ans)
# Original solution
#!/usr/bin/env python3
from itertools import product
n, m = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for i in range(n)]

dp = [[0 for i in range(m+1)] for j in range(n+1)]


# eval
# eval_list = ["+xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]",
#              "+xyz[i-1][0]+xyz[i-1][1]-xyz[i-1][2]",
#              "+xyz[i-1][0]-xyz[i-1][1]+xyz[i-1][2]",
#              "+xyz[i-1][0]-xyz[i-1][1]-xyz[i-1][2]",
#              "-xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]",
#              "-xyz[i-1][0]+xyz[i-1][1]-xyz[i-1][2]",
#              "-xyz[i-1][0]-xyz[i-1][1]+xyz[i-1][2]",
#              "-xyz[i-1][0]-xyz[i-1][1]-xyz[i-1][2]", ]

ans = []
for a, b, c in product([1, -1], repeat=3):
    for i in range(1, n+1):
        for j in range(1, min(i+1, m+1)):
            tmp = xyz[i-1][0]*a + xyz[i-1][1]*b + xyz[i-1][2]*c
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-1] + tmp)

    ans.append(dp[-1][-1])
print((max(ans)))


# Optimized solution
#!/usr/bin/env python3
from itertools import product
n, m = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for i in range(n)]

dp = [[0 for i in range(m+1)] for j in range(n+1)]


# eval
# eval_list = ["+xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]",
#              "+xyz[i-1][0]+xyz[i-1][1]-xyz[i-1][2]",
#              "+xyz[i-1][0]-xyz[i-1][1]+xyz[i-1][2]",
#              "+xyz[i-1][0]-xyz[i-1][1]-xyz[i-1][2]",
#              "-xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]",
#              "-xyz[i-1][0]+xyz[i-1][1]-xyz[i-1][2]",
#              "-xyz[i-1][0]-xyz[i-1][1]+xyz[i-1][2]",
#              "-xyz[i-1][0]-xyz[i-1][1]-xyz[i-1][2]", ]

ans = 0
for a, b, c in product([1, -1], repeat=3):
    total = []
    for x, y, z in xyz:
        s = x*a+y*b+z*c
        total.append(s)
    total.sort(reverse=True)
    ans = max(ans, sum(total[:m]))
print(ans)
# Original solution
n, m = list(map(int, input().split()))

x = []
y = []
z = []

for i in range(n):
    X, Y, Z = list(map(int, input().split()))
    x.append(X)
    y.append(Y)
    z.append(Z)

sign = [1, -1]

ans = []

for j in sign:
    for k in sign:
        for l in sign:
            a = []
            for i in range(n):
                a.append(x[i] * j + y[i] * k + z[i] * l)
            a.sort(reverse=True)
            ans.append(sum(a[:m]))
print((max(ans)))


# Optimized solution
n, m = list(map(int, input().split()))

cake = [list(map(int, input().split())) for i in range(n)]

box = [[[[] for i in range(2)] for j in range(2)] for k in range(2)]
ans = 0
for i in range(2):
    for j in range(2):
        for k in range(2):
            worth = 0
            for x, y, z in cake:
                if i == 1:
                    x = -x
                if j == 1:
                    y = -y
                if k == 1:
                    z = -z
                box[i][j][k].append(x+y+z)
            box[i][j][k].sort(reverse=True)
            ans = max(ans, sum(box[i][j][k][:m]))

print(ans)
# Original solution
import itertools


N, M = list(map(int, input().split()))
lst = [list(map(int, input().rstrip().split())) for n in range(N)]
num = [i for i in range(N)]
maximum = -float("inf")
for p in itertools.combinations(num, M):
    m = sum(abs(sum(lst[n][i] for n in p)) for i in range(3))
    maximum = max(maximum, m)

print(maximum)


# Optimized solution
N, M = list(map(int, input().split()))
lst = [list(map(int, input().rstrip().split())) for n in range(N)]
maximum = -float("inf")
for i in [-1, 1]:
    for j in [-1, 1]:
        for k in [-1, 1]:
            sum_lst = []
            for n in range(N):
                num = lst[n][0] * i + lst[n][1] * j + lst[n][2] * k
                sum_lst.append(num)
            maximum = max(abs(sum(sorted(sum_lst)[:M])), maximum)
            
print(maximum)
# Original solution
import itertools
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
cakes = []
for _ in range(N):
    x, y, z = list(map(int, input().split()))
    cakes.append((x, y, z))

ans = 0
for i in itertools.combinations(cakes, M):
    sx, sy, sz = 0, 0, 0
    for j in i:
        x, y, z = j
        sx = sx + x
        sy = sy + y
        sz = sz + z
    ans = max(ans, abs(sx) + abs(sy) + abs(sz))
print(ans)


# Optimized solution
N, M = list(map(int, input().split()))
cakes = []
for _ in range(N):
    x, y, z = list(map(int, input().split()))
    cakes.append((x, y, z))

ans = 0
for i in range(2**3):
    op1, op2, op3 = 1, 1, 1
    for idx, j in enumerate(bin(i)[2:][::-1], 1):
        j = int(j)
        if idx == 1:
            op1 = 1 if j == 0 else -1
        elif idx == 2:
            op2 = 1 if j == 0 else -1
        elif idx == 3:
            op3 = 1 if j == 0 else -1
            
    cakes.sort(reverse=True, key=lambda x: op1 * x[0] + op2 * x[1] + op3 * x[2])
    sx, sy, sz = 0, 0, 0
    for cake in cakes[:M]:
        sx += cake[0]
        sy += cake[1]
        sz += cake[2]
    ans = max(ans, abs(sx) + abs(sy) + abs(sz))
print(ans)
# Original solution
import sys
sys.setrecursionlimit(50000)

n,m=(int(i) for i in input().strip().split(" "))
xs=[]
ys=[]
zs=[]
for i in range(n):
    a,b,c=(int(i) for i in input().strip().split(" "))
    xs.append(a)
    ys.append(b)
    zs.append(c)

def g():
    return "no"
from collections import defaultdict
d=defaultdict(g)
def find(l,m,x,y,z):
    if d[(l,m,x,y,z)]!="no":
        return d[(l,m,x,y,z)]
    if m<=0:
        return abs(x)+abs(y)+abs(z)
    if l<0:
        return abs(x)+abs(y)+abs(z)
    a=find(l-1,m,x,y,z)
    b=find(l-1,m-1,x+xs[l],y+ys[l],z+zs[l])
    d[(l, m, x, y, z)]=max(a,b)
    return d[(l,m,x,y,z)]

print((find(n-1,m,0,0,0)))


# Optimized solution
import sys

sys.setrecursionlimit(50000)

n, m = (int(i) for i in input().strip().split(" "))
xs = []
ys = []
zs = []
for i in range(n):
    a, b, c = (int(i) for i in input().strip().split(" "))
    xs.append(a)
    ys.append(b)
    zs.append(c)

k=0

ar=[]
for i in range(n):
    ar.append(xs[i]+ys[i]+zs[i])
ar.sort(reverse=True)
t=sum(ar[:m])
if t>k:
    k=t

ar=[]
for i in range(n):
    ar.append(xs[i]+ys[i]-zs[i])
ar.sort(reverse=True)
t=sum(ar[:m])
if t>k:
    k=t

ar=[]
for i in range(n):
    ar.append(xs[i]-ys[i]+zs[i])
ar.sort(reverse=True)
t=sum(ar[:m])
if t>k:
    k=t

ar=[]
for i in range(n):
    ar.append(-1*xs[i]+ys[i]+zs[i])
ar.sort(reverse=True)
t=sum(ar[:m])
if t>k:
    k=t

ar=[]
for i in range(n):
    ar.append(xs[i]-ys[i]-zs[i])
ar.sort(reverse=True)
t=sum(ar[:m])
if t>k:
    k=t

ar=[]
for i in range(n):
    ar.append(-xs[i]+ys[i]-zs[i])
ar.sort(reverse=True)
t=sum(ar[:m])
if t>k:
    k=t

ar=[]
for i in range(n):
    ar.append(-xs[i]-ys[i]+zs[i])
ar.sort(reverse=True)
t=sum(ar[:m])
if t>k:
    k=t

ar=[]
for i in range(n):
    ar.append(-xs[i]-ys[i]-zs[i])
ar.sort(reverse=True)
t=sum(ar[:m])
if t>k:
    k=t
print(k)
# Original solution
import sys
sys.setrecursionlimit(1000000000)


N, M = list(map(int, input().split()))
x, y, z = [], [], []
for _ in range(N):
    xyz = list(map(int, input().split()))
    x += [xyz[0]]
    y += [xyz[1]]
    z += [xyz[2]]


def func(i, j, fx, fy, fz, v):
    if i > N - 1 or j > M - 1:
        return v
    r1 = func(i + 1, j + 1, fx + x[i], fy + y[i], fz + z[i],
              abs(fx + x[i]) + abs(fy + y[i]) + abs(fz + z[i]))
    r2 = func(i + 1, j, fx, fy, fz, v)
    v = max(r1, r2)
    return v


print((func(0, 0, 0, 0, 0, 0)))


# Optimized solution
N, M = list(map(int, input().split()))
xyz = []
ans = 0
for _ in range(N):
    xyz += [list(map(int, input().split()))]
for b in range(2 ** 3):
    pm = [1] * 3
    for j in range(3):
        if (b >> j) & 1:
            pm[j] *= -1
    r = []
    for i in range(N):
        r += [pm[0] * xyz[i][0] + pm[1] * xyz[i][1] + pm[2] * xyz[i][2]]
    r.sort(reverse=True)
    ans = max(ans, sum(r[:M]))
print(ans)
# Original solution
from itertools import combinations

N,M = list(map(int,input().split())) # <=1000
xyz = [list(map(int,input().split())) for _ in range(N)]
x = [i[0] for i in xyz]
y = [i[1] for i in xyz]
z = [i[2] for i in xyz]
if  M == 0:
    print((0))
    exit()
result = 0
for s in combinations(list(range(N)),M):
    tx = ty = tz = 0
    for i in s:
        tx += x[i]
        ty += y[i]
        tz += z[i]
    result = max(result,abs(tx)+abs(ty)+abs(tz))
print(result)


# Optimized solution
import itertools

N,M = list(map(int,input().split())) # <=1000
xyz = [list(map(int,input().split())) for _ in range(N)]
if  M == 0:
    print((0))
    exit()
result = 0
L = [[0] * N for i in range(8)]
for i,j in enumerate(itertools.product((-1,1),repeat=3)):
    for k,l in enumerate(xyz):
        L[i][k] = l[0] * j[0] + l[1] * j[1] + l[2] * j[2]
    L[i] = sorted(L[i],reverse=True)
print((max([sum(i[:M]) for i in L])))
# Original solution
inf = float('inf')
mod = 10**9+7
from itertools import product, permutations, combinations, combinations_with_replacement
import bisect


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

result = -inf

kireisa = 0
oishisa = 0
ninkido = 0

for i in combinations(list(range(N)), M):

    kireisa = 0
    oishisa = 0
    ninkido = 0
    for j in i:
        kireisa += xyz[j][0]
        oishisa += xyz[j][1]
        ninkido += xyz[j][2]
    tmp = abs(kireisa)+abs(oishisa)+abs(ninkido)
    result = max(result,tmp)

print(result)
 

# Optimized solution
N, M = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for i in range(N)]
tmp = [[0]*N for i in range(8)]

for n, _ in enumerate(xyz):
    x,y,z = _
    tmp[0][n] = x+y+z
    tmp[1][n] = x+y-z
    tmp[2][n] = x-y+z
    tmp[3][n] = x-y-z
    tmp[4][n] = -x+y+z
    tmp[5][n] = -x+y-z
    tmp[6][n] = -x-y+z
    tmp[7][n] = -x-y-z

result = -float("inf")
for i in range(8):
    result = max(result, sum(sorted(tmp[i], reverse=True)[:M]))
print(result)
# Original solution
n,m=list(map(int,input().split()))
xyz=[list(map(int,input().split())) for _ in range(n)]
t=[[0]*n for _ in range(8)]
i=0
for x,y,z in xyz:
    t[0][i]=x+y+z
    t[1][i]=-x+y+z
    t[2][i]=x-y+z
    t[3][i]=x+y-z
    t[4][i]=-x-y+z
    t[5][i]=x-y-z
    t[6][i]=-x+y-z
    t[7][i]=-x-y-z
    i+=1
ans=0
for tk in t:
    tk.sort(reverse=True)
    ans=max(ans,sum(tk[:m]))
print(ans)


# Optimized solution
n, m = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for _ in range(n)]
if m==0:
    print((0))
    exit()
t = [[0] * n for _ in range(4)]
i = 0
for x, y, z in xyz:
    t[0][i] = x + y + z
    t[1][i] = -x + y + z
    t[2][i] = x - y + z
    t[3][i] = x + y - z
    i += 1
ans = 0
for tk in t:
    tk.sort()
    ans = max(ans, -sum(tk[:m]),sum(tk[-m:]))
print(ans)
# Original solution
#ABC100-D Patisserie ABC
"""
+を採用するか-を採用するかで各評価値が2通りなので、
2**3の全探索を行えば良い
"""
import sys
from copy import deepcopy
from operator import itemgetter
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n,m = list(map(int,readline().split()))
xyz = []
for i in range(n):
    xyz.append(list(map(int,readline().split())))

ans = 0

for i in range(1<<4):
    res = [0]*n
    for j in range(3):
        if i>>j&1==1:
            for k in range(n):
                res[k] += -xyz[k][j]
        else:
            for k in range(n):
                res[k] += xyz[k][j]
    
    res.sort(reverse=True)
    res2 = abs(sum(res[:m]))

    ans = max(ans,res2)


print(ans)

    

# Optimized solution
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n,m = list(map(int,readline().split()))
lst1 = []
for i in range(n):
    lst1.append(list(map(int,readline().split())))

ans = 0
for i in range(1<<4):
    res = [0]*n
    for j in range(3):
        if i>>j&1:
            for k in range(n):
                res[k] += lst1[k][j]
        else:
            for k in range(n):
                res[k] -= lst1[k][j]
    res.sort(reverse=True)
    ans = max(ans,sum(res[:m]))

print(ans)