module subprogram
	implicit none
contains
	subroutine heapsort(n,array)
	integer,intent(in) :: n
	integer(8),intent(inout) :: array(1:n)
  
	integer ::i,k,j,l
	double precision :: t
  
	if(n.le.0)then
		write(6,*)"Error, at heapsort"; stop
	endif
	if(n.eq.1)return

	l=n/2+1
	k=n
	do while(k.ne.1)
		if(l.gt.1)then
			l=l-1
			t=array(L)
		else
			t=array(k)
			array(k)=array(1)
			k=k-1
			if(k.eq.1) then
			array(1)=t
			exit
			endif
		endif
		i=l
		j=l+l
		do while(j.le.k)
			if(j.lt.k)then
			if(array(j).lt.array(j+1))j=j+1
			endif
			if (t.lt.array(j))then
			array(i)=array(j)
			i=j
			j=j+j
			else
			j=k+1
			endif
		enddo
		array(i)=t
	enddo
	return
	end subroutine heapsort
end module subprogram


program main
	use subprogram
	implicit none
	integer N, M, i, j, xfugo(1:8), yfugo(1:8), zfugo(1:8)
	integer(8) Sans(1:8)
	integer(8), allocatable :: x(:), y(:), z(:), S(:)
	read(*, *) N, M
	allocate(x(1: N))
	allocate(y(1: N))
	allocate(z(1: N))
	allocate(S(1: N))
	do i = 1, N
		read(*, *) x(i), y(i), z(i)
	end do
	Sans(1:8) = 0
	xfugo(1) = 1; yfugo(1) = 1; zfugo(1) = 1
	xfugo(2) = -1; yfugo(2) = 1; zfugo(2) = 1
	xfugo(3) = 1; yfugo(3) = -1; zfugo(3) = 1
	xfugo(4) = 1; yfugo(4) = 1; zfugo(4) = -1
	xfugo(5) = -1; yfugo(5) = -1; zfugo(5) = 1
	xfugo(6) = -1; yfugo(6) = 1; zfugo(6) = -1
	xfugo(7) = 1; yfugo(7) = -1; zfugo(7) = -1
	xfugo(8) = -1; yfugo(8) = -1; zfugo(8) = -1
	do i = 1, 8
		do j = 1, N
			S(j) = xfugo(i) * x(j)  +  yfugo(i) * y(j)  +  zfugo(i) * z(j)
		end do
		call heapsort(N,S)
		S = S(N:1:-1)
		do j = 1, M
			Sans(i) = Sans(i) + S(j)
		end do
	end do
	write(*, *) maxval(Sans)
end program main