(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\Space))
  "Note that the returned string will be reused."
  (let ((buffer (gensym))
        (character (gensym))
        (idx (gensym)))
    `(let ((,buffer (load-time-value (make-string ,buffer-size
                                                  :element-type 'base-char))))
       (declare (simple-base-string ,buffer))
       (loop for ,character of-type base-char =
                #-swank (code-char (read-byte ,in nil #.(char-code #\Newline)))
                #+swank (read-char ,in nil #\Newline)
             for ,idx from 0
             until (char= ,character #\Newline)
             do (setf (schar ,buffer ,idx) ,character)
             finally (setf (schar ,buffer ,idx) ,terminate-char)
                     (return (values ,buffer ,idx))))))

(defmacro split-ints-bind (vars string &body body)
  (let ((pos1 (gensym))
	(pos2 (gensym))
	(s (gensym)))
    (labels ((expand (vars &optional init-pos1)
	       (if (null vars)
		   body
		   `((let* ((,pos1 ,(or init-pos1 `(1+ ,pos2)))
			    (,pos2 (position #\space ,s :start ,pos1 :test #'char=))
			    (,(car vars) (parse-integer ,s :start ,pos1 :end ,pos2)))
		       ,@(expand (cdr vars)))))))
      `(let ((,s ,string))
         (declare (string ,s))
	 ,@(expand vars 0)))))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (let* ((n (read))
         (m (read))
         (seq (make-array n :element-type 'list)))
    (dotimes (i n)
      (split-ints-bind (x y z) (buffered-read-line 40)
        (setf (aref seq i) (list x y z))))
    (println
     (max (loop with seq = (sort seq #'> :key (lambda (tri) (+ (first tri) (second tri) (third tri))))
                for i below m
                sum (+ (first (aref seq i)) (second (aref seq i)) (third (aref seq i))))
          (loop with seq = (sort seq #'> :key (lambda (tri) (+ (- (first tri)) (second tri) (third tri))))
                for i below m
                sum (+ (- (first (aref seq i))) (second (aref seq i)) (third (aref seq i))))
          (loop with seq = (sort seq #'> :key (lambda (tri) (+ (first tri) (- (second tri)) (third tri))))
                for i below m
                sum (+ (first (aref seq i)) (- (second (aref seq i))) (third (aref seq i))))
          (loop with seq = (sort seq #'> :key (lambda (tri) (+ (first tri) (second tri) (- (third tri)))))
                for i below m
                sum (+ (first (aref seq i)) (second (aref seq i)) (- (third (aref seq i)))))
          (loop with seq = (sort seq #'> :key (lambda (tri) (+ (- (first tri)) (- (second tri)) (third tri))))
                for i below m
                sum (+ (- (first (aref seq i))) (- (second (aref seq i))) (third (aref seq i))))
          (loop with seq = (sort seq #'> :key (lambda (tri) (+ (first tri) (- (second tri)) (- (third tri)))))
                for i below m
                sum (+ (first (aref seq i)) (- (second (aref seq i))) (- (third (aref seq i)))))
          (loop with seq = (sort seq #'> :key (lambda (tri) (+ (- (first tri)) (second tri) (- (third tri)))))
                for i below m
                sum (+ (- (first (aref seq i))) (second (aref seq i)) (- (third (aref seq i)))))
          (loop with seq = (sort seq #'> :key (lambda (tri) (+ (- (first tri)) (- (second tri)) (- (third tri)))))
                for i below m
                sum (+ (- (first (aref seq i))) (- (second (aref seq i))) (- (third (aref seq i)))))))))

#-swank(main)


Measured memory_bytes: 24552