open Batteries

let () =
  let n, m = Scanf.scanf "%d %d" (fun x y -> x, y) in
  let cakes = Array.init n (fun i ->
    Scanf.scanf " %d %d %d" (fun x y z -> (i, x, y, z))) in
  (0--7) |> Enum.map (fun b ->
    let s = Array.init 3 (fun i -> if b land (1 lsl i) <> 0 then 1 else -1) in
    let sx, sy, sz = List.init n (fun i ->
      let _, x, y, z = cakes.(i) in
      (s.(0) * x + s.(1) * y + s.(2) * z, x, y, z))
    |> List.sort (fun x y -> compare y x)
    |> List.take m
    |> List.fold_left (fun (sx, sy, sz) (_,x,y,z) -> (sx+x, sy+y, sz+z)) (0, 0, 0)
    in
    abs sx + abs sy + abs sz)
  |> Enum.fold max 0 |> Printf.printf "%d\n"
