using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Remoting.Contexts;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;

        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }

            var res = line[index];
            index++;
            return res;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }

        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }

        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }

        public uint NextUint()
        {
            return uint.Parse(Next());
        }
    }

    struct Cake
    {
        public long X, Y, Z;

        public Cake(long x, long y, long z)
        {
            X = x;
            Y = y;
            Z = z;
        }
    }

    class Program
    {
        private int N, M;
        private Cake[] Cakes;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            M = sc.NextInt();
            Cakes = new Cake[N];
            for (int i = 0; i < N; i++)
            {
                Cakes[i] = new Cake(sc.NextLong(), sc.NextLong(), sc.NextLong());
            }
        }


        public void Solve()
        {
            Scan();
            long ans = Score(1, 1, 1);
            ans = Math.Max(ans, Score(1, 1, -1));
            ans = Math.Max(ans, Score(1, -1, 1));
            ans = Math.Max(ans, Score(1, -1, -1));
            ans = Math.Max(ans, Score(-1, 1, 1));
            ans = Math.Max(ans, Score(-1, 1, -1));
            ans = Math.Max(ans, Score(-1, -1, 1));
            ans = Math.Max(ans, Score(-1, -1, -1));
            Console.WriteLine(ans);
        }

        private long Score(int a, int b, int c)
        {
            var dp = new long[M + 1, N + 1];
            var bb = new bool[M + 1, N + 1];
            for (int i = 0; i <= M; i++)
            {
                for (int j = 0; j <= N; j++)
                {
                    dp[i, j] = long.MinValue;
                }
            }
            dp[0, 0] = 0;
            bb[0, 0] = true;
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j <= M; j++)
                {
                    if (!bb[j, i]) continue;
                    dp[j, i + 1] = Math.Max(dp[j, i + 1], dp[j, i]);
                    bb[j, i + 1] = true;
                    if (j < M)
                    {
                        dp[j + 1, i + 1] = Math.Max(dp[j + 1, i + 1],
                            dp[j, i] + Cakes[i].X * a + Cakes[i].Y * b + Cakes[i].Z * c);
                        bb[j + 1, i + 1] = true;
                    }
                }

            }
            return (dp[M, N]);
        }


        static void Main() => new Program().Solve();
    }

}


Measured memory_bytes: 29640