#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int satis[50][3];
int n, m;
typedef pair<int, int> P;
typedef pair<int, P> PP;
map<PP, int> memo;
int dfs(int idx, int lev1, int rest){
  PP arg = PP(idx, P(lev1, rest));
  if(memo.count(arg)) return memo[arg];
  if(idx == n) return 0;
  int res = -INF;
  for(int lev2 = 0; lev2 <= rest; lev2++){
    int maxp = satis[idx][2];
    for(int u2 = 0; u2 <= lev2; u2++){
      for(int u1 = 0; u1 <= lev1; u1++){
        if(u2 == 0 && u1 == 0) continue;
        if(u1 + u2 > 8) continue;
        maxp = max(maxp, satis[idx][0] * u2 + satis[idx][1] * u1);
      }
    }
    res = max(res, dfs(idx + 1, lev2, rest - lev2) + maxp);
  }
  return memo[arg] = res;
}

int main(){
  while(cin>>n>>m){
    memo.clear();
    REP(i, n) REP(j, 3) cin>>satis[i][j];
    cout<<dfs(0, 0, m)<<endl;
  }
  return 0;
}