let rec take n = function
  | [] -> []
  | x :: xs ->
      if n = 0 then []
      else x :: take (n - 1) xs

let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let xyzs = Array.to_list @@ Array.init n @@ fun _ ->
    Scanf.scanf "%d %d %d\n" @@ fun x y z -> x, y, z in
  begin List.concat @@ List.map (fun sx ->
    List.concat @@ List.map (fun sy ->
      List.map (fun sz ->
        List.sort (fun (x, y, z) (x', y', z') ->
          compare (sx * x' + sy * y' + sz * z') (sx * x + sy * y + sz * z)) xyzs
        |> take m
        |> List.fold_left (fun (x, y, z) (x', y', z') -> (x + x', y + y', z + z')) (0, 0, 0)
        |> (fun (x, y, z) -> abs x + abs y + abs z)) [ 1; -1 ]) [ 1; -1 ]) [ 1; -1 ] end
  |> List.fold_left max min_int 
  |> Printf.printf "%d\n"