macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input!{
        source = src,
        n: isize,
        m: usize,
        an: [(i64, i64, i64); n],
    }


    let mut vec: Vec<i64> = Vec::new();
    let mut bn = an;

    ///////////////////////1
    bn.sort_by(|x, y| {
        let yy = y.0 + y.1 + y.2;
        (x.0 + x.1 + x.2).cmp(&yy)
    });
    let c = bn.iter().take(m).fold((0, 0, 0), |a, x| (a.0 + x.0, a.1 + x.1, a.2 + x.2));
    vec.push(c.0.abs() + c.1.abs() + c.2.abs());

    ///////////////////////2
    bn.sort_by(|x, y| {
        let yy = y.0 + y.1 - y.2;
        (x.0 + x.1 - x.2).cmp(&yy)
    });
    let c = bn.iter().take(m).fold((0, 0, 0), |a, x| (a.0 + x.0, a.1 + x.1, a.2 + x.2));
    vec.push(c.0.abs() + c.1.abs() + c.2.abs());

    ///////////////////////3
    bn.sort_by(|x, y| {
        let yy = y.0 - y.1 + y.2;
        (x.0 - x.1 + x.2).cmp(&yy)
    });
    let c = bn.iter().take(m).fold((0, 0, 0), |a, x| (a.0 + x.0, a.1 + x.1, a.2 + x.2));
    vec.push(c.0.abs() + c.1.abs() + c.2.abs());

    ///////////////////////4
    bn.sort_by(|x, y| {
        let yy = y.0 - y.1 - y.2;
        (x.0 - x.1 - x.2).cmp(&yy)
    });
    let c = bn.iter().take(m).fold((0, 0, 0), |a, x| (a.0 + x.0, a.1 + x.1, a.2 + x.2));
    vec.push(c.0.abs() + c.1.abs() + c.2.abs());

    ///////////////////////5
    bn.sort_by(|x, y| {
        let yy = 0 - y.0 + y.1 + y.2;
        (0 - x.0 + x.1 + x.2).cmp(&yy)
    });
    let c = bn.iter().take(m).fold((0, 0, 0), |a, x| (a.0 + x.0, a.1 + x.1, a.2 + x.2));
    vec.push(c.0.abs() + c.1.abs() + c.2.abs());

    ///////////////////////6
    bn.sort_by(|x, y| {
        let yy = 0 - y.0 + y.1 - y.2;
        (0 - x.0 + x.1 - x.2).cmp(&yy)
    });
    let c = bn.iter().take(m).fold((0, 0, 0), |a, x| (a.0 + x.0, a.1 + x.1, a.2 + x.2));
    vec.push(c.0.abs() + c.1.abs() + c.2.abs());

    ///////////////////////7
    bn.sort_by(|x, y| {
        let yy = 0 - y.0 - y.1 + y.2;
        (0 - x.0 - x.1 + x.2).cmp(&yy)
    });
    let c = bn.iter().take(m).fold((0, 0, 0), |a, x| (a.0 + x.0, a.1 + x.1, a.2 + x.2));
    vec.push(c.0.abs() + c.1.abs() + c.2.abs());

    ///////////////////////8
    bn.sort_by(|x, y| {
        let yy = 0 - y.0 - y.1 - y.2;
        (0 - x.0 - x.1 - x.2).cmp(&yy)
    });
    let c = bn.iter().take(m).fold((0, 0, 0), |a, x| (a.0 + x.0, a.1 + x.1, a.2 + x.2));
    vec.push(c.0.abs() + c.1.abs() + c.2.abs());

    let ans = match vec.iter().max() {
        Some(x) => *x,
        None    => 0,
    };

    return ans.to_string();
}




Measured memory_bytes: 4352