#include <iostream>
#include <cstdio>
#include <vector>
#include <valarray>
#include <cassert>

using namespace std;
typedef long long ll;

int n;
int g[55][9][9];
int dp[55][55][9];
int used[55][55][9];

int solve(int u, int m, int b = 0) {
	if (u == n) return 0;
	if (used[u][m][b]) return dp[u][m][b];
	used[u][m][b] = true;
	int res = -1000000;
	for (int i = 0; i <= min(8, m); i++) {
		res = max(res, solve(u+1, m-i, i) + g[u][i][b]);
	}
	return dp[u][m][b] = res;
}

int main() {
	int m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		for (int j = 0; j <= 8; j++) {
			for (int k = 0; k <= 8; k++) {
				g[i][j][k] = c;
				for (int x = 0; x <= j; x++) {
					for (int y = 0; y <= k; y++) {
						if (!x && !y) continue;
						if (x + y > 8) continue;
						int res = x*a + y*b;
						g[i][j][k] = max(g[i][j][k], res);
					}
				}
			}
		}
	}
	cout << solve(0, m) << endl;
	return 0;
}