#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < (n); ++i)

signed main() {
  int n, m;
  cin >> n >> m;

  int x[1010][3];
  rep(i, n) rep(j, 3) cin >> x[i][j];

  int ans = 0;
  rep(bit, 8) {
    vector<int> v(n);
    rep(i, n) rep(j, 3) v[i] += (bit & (1 << j) ? -1 : 1) * x[i][j];

    sort(v.rbegin(), v.rend());
    ans = max(ans, accumulate(v.begin(), v.begin() + m, 0ll));
  }

  cout << ans << endl;
}
