#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int dp[51][51][51][51]={};
const int MIN=INT_MIN/10;
int dfs(int live,int lv0,int lv1,int lv2,vi &a,vi &b,vi &c){
	if(dp[live][lv0][lv1][lv2]!=MIN){
		return dp[live][lv0][lv1][lv2];
	}
	if(live==a.size()){
		return 0;
	}
	int ret=MIN;
	REP(k,lv2+1){
		REP(i,min(8,k)+1){
			REP(j,8-i+1){
				if(lv1>=j){
					int plus=0;
					if(i==0&&j==0){
						plus=c[live];
					}else{
						plus=a[live]*i+b[live]*j;
					}
					ret=max(ret,dfs(live+1,lv0+lv1,k,lv2-k,a,b,c)+plus);
				}
			}
		}
	}
	return dp[live][lv0][lv1][lv2]=ret;
}
int main(){
	int n,m;
	cin>>n>>m;
	vi a(n),b(n),c(n);
	REP(i,51)REP(j,51)REP(k,51)REP(l,51)dp[i][j][k][l]=MIN;
	REP(i,n){
		cin>>a[i]>>b[i]>>c[i];
	}
	cout<<dfs(0,0,0,m,a,b,c)<<endl;

	//REP(i,51){
	//	int aa=0;
	//	REP(j,51)REP(k,51)REP(l,51){
	//		aa=max(aa,dp[i][j][k][l]);
	//	}
	//	cout<<i<<" "<<aa<<endl;
	//}
}