let greedy l m = 
	let rec greedy l m sum = 
    	if m = 0 then sum else
    	match l with
        	[] -> sum
            | (x, y, z) :: rest -> greedy rest (m - 1) (sum + x + y + z)
    in greedy (List.sort (fun (x, y, z) (x2, y2, z2) -> x2 + y2 + z2 - x - y - z) l) m 0
let change l x y z = 
	let rec change l ret = 
    	match l with
        	[] -> ret
            | (x2, y2, z2) :: rest -> change rest ((x2 * x, y2 * y, z2 * z) :: ret)
    in change l []
let max l = 
	let rec max l ret = 
    	match l with
        	[] -> ret
            | first :: rest -> max rest ((fun x y -> if x < y then y else x) first ret)
    in max l 0
let ans l m = 
	max (List.rev_map (fun x -> greedy x m) [
    	change l 1 1 1; change l 1 1 (-1); change l 1 (-1) 1; change l 1 (-1) (-1);
        change l (-1) 1 1; change l (-1) 1 (-1); change l (-1) (-1) 1; change l (-1) (-1) (-1)])
let getList n = 
	let rec getList n l = if n = 0 then l 
    	else getList (n - 1) (Scanf.scanf " %d %d %d" (fun x y z -> (x, y, z) :: l))
    in getList n []
let calc = Scanf.scanf "%d %d" (fun n m -> ans (getList n) m)
let main = print_int calc
	