program test

integer(8) :: i,j,k
integer(8) :: x(1000),y(1000),z(1000),value(1000)
integer(8) :: dp(0:1000,0:1000)=0,value_max=0
integer :: x_sig(8) = (/-1,-1,-1,-1, 1, 1, 1, 1/)
integer :: y_sig(8) = (/-1,-1, 1, 1,-1,-1, 1, 1/)
integer :: z_sig(8) = (/-1, 1,-1, 1,-1, 1,-1, 1/)

read(*,*) n,m

do i=1,n
	read(*,*) x(i),y(i),z(i)
enddo


do ii= 1,8
	dp = 0
	do i=1,n
		value(i) = x_sig(ii)*x(i) + y_sig(ii)*y(i) + z_sig(ii)*z(i)
	enddo
	
	do i=1,n
		do j=1,m
			dp(i,j) = max(dp(i-1,j) , dp(i-1,j-1)+value(i))
		enddo
	enddo
	
	value_max = max(value_max,dp(n,m))
	
enddo

write(*,*) value_max


end program