def main():

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

    X = [list(map(int, input().split())) for _ in range(N)]



    ans = 0

    for i in [-1,1]:

        for j in [-1,1]:

            for k in [-1,1]:

                tmp = []

                for x, y, z in X:

                    tmp.append(i*x + j*y + k*z)

                tmp.sort(reverse=True)

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

    

    print(ans)



main()
def main():

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

    x = [0] * N

    y = [0] * N

    z = [0] * N

    for i in range(N):

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



    ans = 0

    for i in [-1,1]:

        for j in [-1,1]:

            for k in [-1,1]:

                cand_list = []

                for n in range(N):

                    tmp = i * x[n] + j * y[n] + k * z[n]

                    cand_list.append(tmp)

                cand_list.sort(reverse=True)

                a = 0

                for m in range(M):

                    a += cand_list[m]

                ans = max(ans, a)



    print(ans)





    





if __name__ == "__main__":

    main()
def main():
    N, M = list(map(int, input().split()))
    X = [list(map(int, input().split())) for _ in range(N)]
    ans = 0
    for i in [-1, 1]:
        for j in [-1, 1]:
            for k in [-1, 1]:
                tmp = []
                for x, y, z in X:
                    tmp.append(i * x + j * y + k * z)
                tmp.sort(reverse=True)
                ans = max(ans, sum(tmp[:M]))
    print(ans)


main()

def main():
    N, M = list(map(int, input().split()))
    x = [0] * N
    y = [0] * N
    z = [0] * N
    for i in range(N):
        x[i], y[i], z[i] = list(map(int, input().split()))
    ans = 0
    for i in [-1, 1]:
        for j in [-1, 1]:
            for k in [-1, 1]:
                cand_list = []
                for n in range(N):
                    tmp = i * x[n] + j * y[n] + k * z[n]
                    cand_list.append(tmp)
                cand_list.sort(reverse=True)
                a = 0
                for m in range(M):
                    a += cand_list[m]
                ans = max(ans, a)
    print(ans)


if __name__ == "__main__":
    main()

-    X = [list(map(int, input().split())) for _ in range(N)] +    x = [0] * N +    y = [0] * N +    z = [0] * N +    for i in range(N): +        x[i], y[i], z[i] = list(map(int, input().split())) -                tmp = [] -                for x, y, z in X: -                    tmp.append(i * x + j * y + k * z) -                tmp.sort(reverse=True) -                ans = max(ans, sum(tmp[:M])) +                cand_list = [] +                for n in range(N): +                    tmp = i * x[n] + j * y[n] + k * z[n] +                    cand_list.append(tmp) +                cand_list.sort(reverse=True) +                a = 0 +                for m in range(M): +                    a += cand_list[m] +                ans = max(ans, a) -main() +if __name__ == "__main__": +    main()