open Batteries
let () =
  let n,m = Scanf.scanf "%d %d " (fun a b -> a,b) in
  let lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d %d %d " (fun a b c -> a,b,c)) in

  let res = ref 0 in

  for i = 0 to 1 do
    let i = if i = 0 then -1 else 1 in
    for j = 0 to 1 do
      let j = if j = 0 then -1 else 1 in
      for k = 0 to 1 do
        let k = if k = 0 then -1 else 1 in
        let lst = List.map (fun (x,y,z) -> x*i + y*j + z*k) lst in
        let lst = List.sort (fun x y -> compare y x) lst in
        let lst = List.filteri (fun i _ -> i < m) lst in
        let sum = List.fold_left (+) 0 lst in
        if sum > !res then res := sum
      done;
    done;
  done;

  Printf.printf "%d\n" !res

