1 #include<iostream>
2 #include<cstdio>
3 #include<cstdlib>
4 #include<cstring>
5 #include<algorithm>
6 #include<cmath>
7 #define inf 0x7fffffff
8 using namespace std;
9 int n,atk;
10 int a[510],b[510],h[510];
11 int dp[510][510];
12 int min(int a,int b){
13 return a<b?a:b;
14 }
15 int chu(int a,int b){
16 return (a-1)/b+1;
17 }
18 int main(){
19 int i,j,k;
20 scanf("%d%d",&n,&atk);
21 for(i=1;i<=n;++i){
22 scanf("%d%d%d",&a[i],&b[i],&h[i]);
23 }
24 for(i=1;i<=n;++i){
25 dp[i][i]=(a[i]+b[i-1]+b[i+1])*chu(h[i],atk);
26 }
27 for(i=1;i<n;++i){
28 for(j=1;j+i<=n;++j){
29 dp[j][j+i]=inf;
30 for(k=j;k<=j+i;++k){
31 dp[j][j+i]=min(dp[j][j+i],dp[j][k-1]+dp[k+1][j+i]+(a[k]+b[j-1]+b[j+i+1])*chu(h[k],atk));
32 }
33 }
34 }
35 printf("%d\n",dp[1][n]);
36 return 0;
37 }