#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_asc(const void* a, const void* b) {
    return *((size_t*)a) < *((size_t*)b) ? -1 : 1;
}

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_i64_asc(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_i64_desc(const void* a, const void* b) {
    return *((int64_t*)a) > * ((int64_t*)b) ? -1 : 1;
}

int compare_c_asc(const void* a, const void* b) {
    return *((char*)a) < *((char*)b) ? -1 : 1;
}

int compare_c_desc(const void* a, const void* b) {
    return *((char*)a) > * ((char*)b) ? -1 : 1;
}

static size_t powSz(const size_t base, const size_t exp) {
    if (exp == 0) {
        return 1;
    }

    if (exp == 1) {
        return base;
    }

    if (exp % 2 == 0) {
        return powSz(base * base, exp / 2);
    }
    else {
        return base * powSz(base, exp - 1);
    }
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

typedef struct {
    int64_t x;
    int64_t y;
    int64_t z;
} _cake;

static _cake cake[1000];

static int compare_f(const void* a, const void* b) {
    const _cake* aP = (_cake*)a;
    const _cake* bP = (_cake*)b;

    return aP->x + aP->y + aP->z > bP->x + bP->y + bP->z ? -1 : 1;
}

int main(void) {
    size_t N, M;

    scanf("%zu %zu\n", &N, &M);
    for (size_t i = 0; i < N; i++) {
        scanf("%"PRId64" %"PRId64" %"PRId64, &(cake[i].x), &(cake[i].y), &(cake[i].z));
        if (i < N - 1) {
            scanf("\n");
        }
    }
    
    int64_t max = INT64_MIN;

    for (size_t X = 0; X < 2; X++) {
        for (size_t Y = 0; Y < 2; Y++) {
            for (size_t Z = 0; Z < 2; Z++) {
                for (size_t i = 0; i < N; i++) {
                    if (X == 0) {
                        cake[i].x = -cake[i].x;
                    }
                    if (Y == 0) {
                        cake[i].y = -cake[i].y;
                    }
                    if (Z == 0) {
                        cake[i].z = -cake[i].z;
                    }
                }

                qsort(cake, N, sizeof(_cake), compare_f);

                int64_t val = 0;

                for (size_t i = 0; i < M; i++) {
                    val += cake[i].x + cake[i].y + cake[i].z;
                }

                if (max < val) {
                    max = val;
                }

                for (size_t i = 0; i < N; i++) {
                    if (X == 0) {
                        cake[i].x = -cake[i].x;
                    }
                    if (Y == 0) {
                        cake[i].y = -cake[i].y;
                    }
                    if (Z == 0) {
                        cake[i].z = -cake[i].z;
                    }
                }
            }
        }
    }

    printf("%"PRId64, max);

    return 0;
}


Measured memory_bytes: 256