#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
using namespace std;
long long a[1005][3],b[1005];
int main()
{
    long long i,n,m,ans=0,ans1=0,j;
    scanf("%lld%lld",&n,&m);
    for(i=0;i<n;i++)
        scanf("%lld%lld%lld",&a[i][0],&a[i][1],&a[i][2]);

    ans=0;
    memset(b,0,sizeof(b));
    for(i=0;i<n;i++)
    {
        if(a[i][0]>0)
            b[i]+=a[i][0];
        else b[i]+=a[i][0];

        if(a[i][1]>0)
            b[i]+=a[i][1];
        else b[i]+=a[i][1];

        if(a[i][2]>0)
            b[i]+=a[i][2];
        else b[i]+=a[i][2];
    }
    sort(b,b+n);
    for(i=n-m;i<n;i++)
        ans+=b[i];
    ans1=max(ans1,ans);

    ans=0;
    memset(b,0,sizeof(b));
    for(i=0;i<n;i++)
    {
        if(a[i][0]>0)
            b[i]+=a[i][0];
        else b[i]+=a[i][0];

        if(a[i][1]>0)
            b[i]+=a[i][1];
        else b[i]+=a[i][1];

        if(a[i][2]>0)
            b[i]-=a[i][2];
        else b[i]-=a[i][2];
    }
    sort(b,b+n);
    for(i=n-m;i<n;i++)
        ans+=b[i];
    ans1=max(ans1,ans);

    ans=0;
    memset(b,0,sizeof(b));
    for(i=0;i<n;i++)
    {
        if(a[i][0]>0)
            b[i]+=a[i][0];
        else b[i]+=a[i][0];

        if(a[i][1]>0)
            b[i]-=a[i][1];
        else b[i]-=a[i][1];

        if(a[i][2]>0)
            b[i]+=a[i][2];
        else b[i]+=a[i][2];
    }
    sort(b,b+n);
    for(i=n-m;i<n;i++)
        ans+=b[i];
    ans1=max(ans1,ans);

    ans=0;
    memset(b,0,sizeof(b));
    for(i=0;i<n;i++)
    {
        if(a[i][0]>0)
            b[i]+=a[i][0];
        else b[i]+=a[i][0];

        if(a[i][1]>0)
            b[i]-=a[i][1];
        else b[i]-=a[i][1];

        if(a[i][2]>0)
            b[i]-=a[i][2];
        else b[i]-=a[i][2];
    }
    sort(b,b+n);
    for(i=n-m;i<n;i++)
        ans+=b[i];
    ans1=max(ans1,ans);

    ans=0;
    memset(b,0,sizeof(b));
    for(i=0;i<n;i++)
    {
        if(a[i][0]>0)
            b[i]-=a[i][0];
        else b[i]-=a[i][0];

        if(a[i][1]>0)
            b[i]+=a[i][1];
        else b[i]+=a[i][1];

        if(a[i][2]>0)
            b[i]+=a[i][2];
        else b[i]+=a[i][2];
    }
    sort(b,b+n);
    for(i=n-m;i<n;i++)
        ans+=b[i];
    ans1=max(ans1,ans);

    ans=0;
    memset(b,0,sizeof(b));
    for(i=0;i<n;i++)
    {
        if(a[i][0]>0)
            b[i]-=a[i][0];
        else b[i]-=a[i][0];

        if(a[i][1]>0)
            b[i]+=a[i][1];
        else b[i]+=a[i][1];

        if(a[i][2]>0)
            b[i]-=a[i][2];
        else b[i]-=a[i][2];
    }
    sort(b,b+n);
    for(i=n-m;i<n;i++)
        ans+=b[i];
    ans1=max(ans1,ans);

    ans=0;
    memset(b,0,sizeof(b));
    for(i=0;i<n;i++)
    {
        if(a[i][0]>0)
            b[i]-=a[i][0];
        else b[i]-=a[i][0];

        if(a[i][1]>0)
            b[i]-=a[i][1];
        else b[i]-=a[i][1];

        if(a[i][2]>0)
            b[i]+=a[i][2];
        else b[i]+=a[i][2];
    }
    sort(b,b+n);
    for(i=n-m;i<n;i++)
        ans+=b[i];
    ans1=max(ans1,ans);

    ans=0;
    memset(b,0,sizeof(b));
    for(i=0;i<n;i++)
    {
        if(a[i][0]>0)
            b[i]-=a[i][0];
        else b[i]-=a[i][0];

        if(a[i][1]>0)
            b[i]-=a[i][1];
        else b[i]-=a[i][1];

        if(a[i][2]>0)
            b[i]-=a[i][2];
        else b[i]-=a[i][2];
    }
    sort(b,b+n);
    for(i=n-m;i<n;i++)
        ans+=b[i];
    ans1=max(ans1,ans);

    printf("%lld\n",ans1);
    return 0;
}


Measured memory_bytes: 256