program patisserie_abc
  implicit none
  integer :: n, m, i
  integer(8) :: x(1000), y(1000), z(1000), s(1000), w(8)
  x = 0_8
  y = 0_8
  z = 0_8
  s = 0_8
  read(*,*) n, m
  if (m.eq.0) then
    write(*,'(i0)') 0
    stop
  end if
  do i = 1, n
    read(*,*) x(i), y(i), z(i)
  end do
  do i = 0, 7
    s = 0_8
    if (btest(i,0)) then
      s = s + x
    else
      s = s - x
    end if
    if (btest(i,1)) then
      s = s + y
    else
      s = s - y
    end if
    if (btest(i,2)) then
      s = s + z
    else
      s = s - z
    end if
    call merge_sort(n,s(1:n))
    w(i) = abs(sum(s(1:m)))
  end do
  write(*,'(i0)') maxval(w)
  stop
contains
  subroutine merge_sort(n,c)
    implicit none
    integer, intent(in)       :: n
    integer(8), intent(inout) :: c(n)
    integer                   :: num, lng, i, ubnd
    num = n
    lng = 1
    do while (num.gt.1)
      do i = 1, num/2
        ubnd = min(2*i*lng,n)
        call merge(c(2*(i-1)*lng+1:(2*i-1)*lng),c((2*i-1)*lng+1:ubnd))
      end do
      lng = 2*lng
      num = (num+1)/2
    end do
    return
  end subroutine merge_sort
  subroutine merge(c1,c2)
    implicit none
    integer(8), intent(inout) :: c1(:), c2(:)
    integer(8)                :: c(size(c1)+size(c2))
    integer                   :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(c1)
    n2 = size(c2)
    do while (i1.le.n1.and.i2.le.n2)
      if (c1(i1).le.c2(i2)) then
        c(i1+i2-1) = c1(i1)
        i1 = i1+1
      else
        c(i1+i2-1) = c2(i2)
        i2 = i2+1
      end if
    end do
    if (i1.le.n1) then
      c(i1+i2-1:n1+n2) = c1(i1:n1)
    else if (i2.le.n2) then
      c(i1+i2-1:n1+n2) = c2(i2:n2)
    end if
    c1 = c(1:n1)
    c2 = c(n1+1:n1+n2)
    return
  end subroutine merge
end program patisserie_abc