using Yorukatsu024.Questions;
using Yorukatsu024.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.CodeDom;

namespace Yorukatsu024.Questions
{
    /// <summary>
    /// ABC100 D
    /// </summary>
    public class QuestionE : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var nm = inputStream.ReadIntArray();
            var n = nm[0];
            var m = nm[1];

            var cakes = new Cake[n];

            for (int i = 0; i < n; i++)
            {
                var xyz = inputStream.ReadLongArray();
                cakes[i] = new Cake(xyz[0], xyz[1], xyz[2]);
            }

            var totalValue = new long?[1 << 3, n + 1, m + 1];
            
            for (int bitFlag = 0; bitFlag < 1 << 3; bitFlag++)
            {
                totalValue[bitFlag, 0, 0] = 0;
                for (int cakeIndex = 0; cakeIndex < n; cakeIndex++)
                {
                    for (int selectedCakeCount = 0; selectedCakeCount <= m; selectedCakeCount++)
                    {
                        // 選ばない場合
                        if (totalValue[bitFlag, cakeIndex, selectedCakeCount].HasValue)
                        {
                            if (totalValue[bitFlag, cakeIndex + 1, selectedCakeCount].HasValue)
                            {
                                totalValue[bitFlag, cakeIndex + 1, selectedCakeCount] =
                                    Math.Max(totalValue[bitFlag, cakeIndex + 1, selectedCakeCount].Value, totalValue[bitFlag, cakeIndex, selectedCakeCount].Value);
                            }
                            else
                            {
                                totalValue[bitFlag, cakeIndex + 1, selectedCakeCount] = totalValue[bitFlag, cakeIndex, selectedCakeCount];
                            }
                        }

                        // 選ぶ場合
                        if (selectedCakeCount < m && totalValue[bitFlag, cakeIndex, selectedCakeCount].HasValue)
                        {
                            var beauty = ((bitFlag & (1 << 0)) > 0 ? 1 : -1) * cakes[cakeIndex].Beauty;
                            var delicious = ((bitFlag & (1 << 1)) > 0 ? 1 : -1) * cakes[cakeIndex].Delicious;
                            var popular = ((bitFlag & (1 << 2)) > 0 ? 1 : -1) * cakes[cakeIndex].Popular;
                            var value = beauty + delicious + popular;
                            totalValue[bitFlag, cakeIndex + 1, selectedCakeCount + 1] = totalValue[bitFlag, cakeIndex, selectedCakeCount] + value;
                        }
                    }
                }
            }

            long max = 0;
            for (int bitFlag = 0; bitFlag < 1 << 3; bitFlag++)
            {
                UpdateWhenLarge(ref max, totalValue[bitFlag, n, m].Value);
            }

            yield return max;
        }

        public static void UpdateWhenSmall<T>(ref T value, T other) where T : IComparable<T>
        {
            if (other.CompareTo(value) < 0)
            {
                value = other;
            }
        }

        public static void UpdateWhenLarge<T>(ref T value, T other) where T : IComparable<T>
        {
            if (other.CompareTo(value) > 0)
            {
                value = other;
            }
        }

    }

    class Cake
    {
        public long Beauty { get; }
        public long Delicious { get; }
        public long Popular { get; }

        public Cake(long beauty, long delicious, long popular)
        {
            Beauty = beauty;
            Delicious = delicious;
            Popular = popular;
        }
    }
}

namespace Yorukatsu024
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionE();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu024.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu024.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 138208