package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"reflect"
	"strconv"
	"unsafe"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	i, err := strconv.Atoi(readString())
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func vi(n int, args ...int) []int {
	res := make([]int, n)
	if len(args) == 0 {
		return res
	}
	v := args[0]
	if v == 0 {
		return res
	}
	for i := 0; i < n; i++ {
		res[i] = v
	}
	return res
}

func vvi(n int, args ...int) [][]int {
	res := make([][]int, n)
	m := n
	if len(args) > 0 {
		m = args[0]
	}
	v := 0
	if len(args) > 1 {
		v = args[1]
	}
	for i := 0; i < n; i++ {
		res[i] = vi(m, v)
	}
	return res
}

var (
	n int
	m int
	x []int64
	y []int64
	z []int64
)

func abs(a int64) int64 {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func main() {
	defer stdout.Flush()

	// readString() string
	// readInt() int
	// readIntSlice(n int) []int
	// readLengthAndSlice() []int
	n = readInt()
	m = readInt()
	x = make([]int64, n)
	y = make([]int64, n)
	z = make([]int64, n)

	for i := 0; i < n; i++ {
		x[i] = readInt64()
		y[i] = readInt64()
		z[i] = readInt64()
	}

	var ans int64

	for _, xs := range []int64{-1, 1} {
		for _, ys := range []int64{-1, 1} {
			for _, zs := range []int64{-1, 1} {
				ts := make([]int64, n)
				for i := 0; i < n; i++ {
					ts[i] = xs*x[i] + ys*y[i] + zs*z[i]
				}
				SortSliceStable(ts, func(i, j int) bool { return ts[i] > ts[j] })
				var ta int64
				for i := 0; i < m; i++ {
					ta += ts[i]
				}
				if ta > ans {
					ans = ta
				}
			}
		}
	}

	println(ans)
}

func SortSliceStable(a interface{}, less func(i, j int) bool) {
	v := reflect.ValueOf(a)

	cptemp, cpback := _sort_cptemper(v)
	fs := _sort_cptemp{cptemp, cpback, less}
	n := v.Len()
	sz := 1
	for sz < n {
		i := 0
		for i+2*sz <= n {
			_sort_merge(fs, i, i+sz, i+2*sz)
			i += 2 * sz
		}
		if i+sz < n {
			_sort_merge(fs, i, i+sz, n)
		}
		sz *= 2
	}
}

type _sort_cptemp struct {
	cptemp func(i, j int)
	cpback func(i, j int)
	less   func(i, j int) bool
}

func _sort_cptemper(v reflect.Value) (func(i, j int), func(i, j int)) {
	n := v.Len()
	sz := int(v.Index(0).Type().Size())
	var cptemp, cpback func(i, j int)
	if sz%8 == 0 {
		m := sz / 8
		tmp := make([]int64, n*m)

		var buf []int64
		sp := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
		sp.Data = v.Pointer()
		sp.Len = n * m
		sp.Cap = n * m
		cptemp = func(i, j int) {
			for k := 0; k < m; k++ {
				tmp[i*m+k] = buf[j*m+k]
			}
		}
		cpback = func(i, j int) {
			for k := 0; k < m; k++ {
				buf[i*m+k] = tmp[j*m+k]
			}
		}
	} else if sz%4 == 0 {
		m := sz / 4
		tmp := make([]int32, n*m)

		var buf []int32
		sp := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
		sp.Data = v.Pointer()
		sp.Len = n * m
		sp.Cap = n * m
		cptemp = func(i, j int) {
			for k := 0; k < m; k++ {
				tmp[i*m+k] = buf[j*m+k]
			}
		}
		cpback = func(i, j int) {
			for k := 0; k < m; k++ {
				buf[i*m+k] = tmp[j*m+k]
			}
		}
	} else if sz%2 == 0 {
		m := sz / 2
		tmp := make([]int16, n*m)

		var buf []int16
		sp := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
		sp.Data = v.Pointer()
		sp.Len = n * m
		sp.Cap = n * m
		cptemp = func(i, j int) {
			for k := 0; k < m; k++ {
				tmp[i*m+k] = buf[j*m+k]
			}
		}
		cpback = func(i, j int) {
			for k := 0; k < m; k++ {
				buf[i*m+k] = tmp[j*m+k]
			}
		}
	} else {
		m := sz
		tmp := make([]int8, n*m)

		var buf []int8
		sp := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
		sp.Data = v.Pointer()
		sp.Len = n * m
		sp.Cap = n * m
		cptemp = func(i, j int) {
			for k := 0; k < m; k++ {
				tmp[i*m+k] = buf[j*m+k]
			}
		}
		cpback = func(i, j int) {
			for k := 0; k < m; k++ {
				buf[i*m+k] = tmp[j*m+k]
			}
		}
	}
	return cptemp, cpback
}

func _sort_merge(fs _sort_cptemp, l, m, r int) {
	cptemp := fs.cptemp
	cpback := fs.cpback
	less := fs.less

	i := l
	j := m
	k := l
	for i < m && j < r {
		if less(j, i) {
			cptemp(k, j)
			j++
		} else {
			cptemp(k, i)
			i++
		}
		k++
	}
	for i < m {
		cptemp(k, i)
		i++
		k++
	}
	for j < r {
		cptemp(k, j)
		j++
		k++
	}
	for i := l; i < k; i++ {
		cpback(i, i)
	}
}


Measured memory_bytes: 768