#include <bits/stdc++.h>

using namespace std;

int main()
{
    unsigned long long  n,m,sum = 0;
    cin >> n >> m;
    while(n--)
    {
        unsigned long long  t,T,tax,cost;
        cin >> t >> T >> tax >> cost;
        unsigned long long

        if(t+m <= T)
        sum += cost;
        else
        {
            unsigned long long  maxsum = tax*m + cost;
            unsigned long long  maxst = T-t;
            for(unsigned long long  i = 2; (i-1)*maxst <= m+maxst; i++)
            {
                unsigned long long  posi = m - maxst*(i-1);
                if(posi <= maxst)
                    posi = 0;
                unsigned long long  a = i*cost + tax*(posi);

                if(a > maxsum)
                    break;
                maxsum = a;
            }
            //cout << maxsum;
            sum += maxsum;
        }
    }
    cout << sum;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m, totalsum = 0;
    cin >> n >>m ;
    for(int i = 0;i  <n; i++)
    {
   int t,maxt,tax,costbus, sum,tempbus;
   cin >> t >> maxt >> tax >> costbus;
        tempbus = t + m;
        sum = costbus;
        if(tempbus > maxt)
        {
            int totaltax = tax*m;
            int totalmony= totaltax +costbus;
            sum = totalmony;
            for(int i = 2; i <= m; i++)
            {
                if(t + m/i > maxt)
                continue;
                    else
                {
                    totalmony = costbus*i;
                    if((t + (m/i) +( m %i)) > maxt)
                        totalmony += ((m/i) +( m %i))*tax;
                }
                if (totalmony > sum)
                {
                    break;
                }
                sum = totalmony;
            }

        }
        totalsum += sum ;
    }
    cout << totalsum;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m, totalsum = 0;
    cin >> n >> m;
    for(int i = 0;i  <n; i++)
    {
        int t,T,tax,costbus,sum = 0;
        cin >> t >> T >> tax >> costbus;
        int maxchild = T-t;
       // cout << maxchild << " *\n";
        if(maxchild >= m)
        {
            totalsum += costbus;
            //cout << costbus << "   ((\n";
            continue;
        }
        sum = tax * m + costbus;
        //cout << sum << "  s"  << endl;
        for(int j = 1;j <= m;j++)
        {
            int k = m - maxchild*j ;
            if (k < 0 || k <= maxchild)
            k = 0;
            //cout << k << "  k\n";

            int p = (costbus*(j+1))+(tax*k);
           // cout<< k << " " << j << " " << p << endl;
               // cout << j << " "<< p << endl;
            if(p > sum)
                break;
            else
                sum = p;
        }
        //cout << sum << endl;
        totalsum += sum;

    }
    cout << totalsum;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int   main()
{
    int n,m;
    unsigned long long sum = 0;
    cin >> n >> m;
    while(n--)
    {
        long long  t,T,tax,cost;
        cin >> t >> T >> tax >> cost;

        long long  maxst = T-t;
        if(t+m <= T)
        {
        //cout << 1 << endl;
        sum += cost;
        }
        else if(maxst <= 0)
        {
             //cout << 2 << endl;
            sum += tax*m + cost;
        }
        else
        {
            unsigned long long  maxsum = tax*m + cost;

            if(tax*(maxst) <= cost)
            {
                sum += maxsum;
               // cout << 11 << " " << maxsum << endl;
            }
            else
            {
                if(m%maxst == 0)
                {
                  //  cout << 110 << " " << (m/maxst) * cost << endl;
                    sum += (m/maxst) * cost;
                }
                else
                {
                    if(tax*(m%maxst) > cost )
                    {
                    //    cout << 12 << " " << ((m/maxst)+1) * cost << endl;
                    sum += ((m/maxst)+1) * cost;
                    }
                    else
                    {
                      //  cout << 13 << " " << (m/maxst) * cost + tax*(m%maxst) << endl;
                        sum += (m/maxst) * cost + tax*(m%maxst);

                    }
                }
            }
        }
    }
    cout << sum;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    unsigned long long  totalsum = 0;
    cin >> n >> m;
    for(int i = 0;i  <n; i++)
    {
        int t,T,tax,costbus;
        unsigned long long sum = 0;
        cin >> t >> T >> tax >> costbus;
        int maxchild = T-t;
        maxchild--;
       // cout << maxchild << " *\n";
        if(maxchild >= m)
        {
            totalsum += costbus;
            //cout << costbus << "   ((\n";
            continue;
        }
        sum = tax * m + costbus;
        //cout << sum << "  s"  << endl;
        for(int j = 1;j <= m;j++)
        {
            int k = m - maxchild*j ;
            if (k < 0 || k <= maxchild)
            k = 0;
            //cout << k << "  k\n";

            unsigned long long p = (costbus*(j+1))+(tax*k);
           // cout<< k << " " << j << " " << p << endl;
               // cout << j << " "<< p << endl;
            if(p > sum)
                break;
            else
                sum = p;
        }
        //cout << sum << endl;
        totalsum += sum;

    }
    cout << totalsum;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    unsigned long long  totalsum = 0;
    cin >> n >> m;
    for(int i = 0;i  <n; i++)
    {
        int t,T,tax,costbus;
        unsigned long long sum = 0;
        cin >> t >> T >> tax >> costbus;
        int maxchild = T-t;
       // cout << maxchild << " *\n";
        if(maxchild >= m)
        {
            totalsum += costbus;
            //cout << costbus << "   ((\n";
            continue;
        }
        sum = tax * m + costbus;
        //cout << sum << "  s"  << endl;
        for(int j = 1;j <= m;j++)
        {
            int k = m - maxchild*j ;
            if (k < 0 || k <= maxchild)
            k = 0;
            //cout << k << "  k\n";

            unsigned long long p = (costbus*(j+1))+(tax*k);
           // cout<< k << " " << j << " " << p << endl;
               // cout << j << " "<< p << endl;
            if(p > sum)
                break;
            else
                sum = p;
        }
        //cout << sum << endl;
        totalsum += sum;

    }
    cout << totalsum;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    unsigned long long totalsum = 0;
    cin >> n >> m;
    for(int i = 0;i  <n; i++)
    {
        unsigned long long t,T,tax,costbus;
        unsigned long long sum = 0;
        cin >> t >> T >> tax >> costbus;
        int maxchild = T-t;
       // cout << maxchild << " *\n";
        if(maxchild >= m)
        {
            totalsum += costbus;
            //cout << costbus << "   ((\n";
            continue;
        }
        sum = tax * m + costbus;
        //cout << sum << "  s"  << endl;
        for(int j = 1;j <= m;j++)
        {
            unsigned long long k = m - maxchild*j ;
            if (k < 0 || k <= maxchild)
            k = 0;
            //cout << k << "  k\n";

            unsigned long long p = (costbus*(j+1))+(tax*k);
           // cout<< k << " " << j << " " << p << endl;
               // cout << j << " "<< p << endl;
            if(p > sum)
                break;
            else
                sum = p;
        }
        //cout << sum << endl;
        totalsum += sum;

    }
    cout << totalsum;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m,sum = 0;
    cin >> n >> m;
    while(n--)
    {
        int t,T,tax,cost;
        cin >> t >> T >> tax >> cost;

        if(t+m <= T)
        sum += cost;
        else
        {
            int maxsum = tax*m + cost;
            int maxst = T-t;
            for(int i = 2; (i-1)*maxst <= m+maxst; i++)
            {
                int posi = m - maxst*(i-1);
                if(posi <= maxst)
                    posi = 0;
                int a = i*cost + tax*(posi);

                if(a > maxsum)
                    break;
                maxsum = a;
            }
            //cout << maxsum;
            sum += maxsum;
        }
    }
    cout << sum;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    unsigned long long  totalsum = 0;
    cin >> n >> m;
    for(int i = 0;i  <n; i++)
    {
        int t,T,tax,costbus;
        unsigned long long sum = 0;
        cin >> t >> T >> tax >> costbus;
        int maxchild = T-t;
       // cout << maxchild << " *\n";
        if(maxchild >= m)
        {
            totalsum += costbus;
            //cout << costbus << "   ((\n";
            continue;
        }
        sum = tax * m + costbus;
        //cout << sum << "  s"  << endl;
        for(int j = 1;j <= m;j++)
        {
            int k = m - maxchild*j ;
            if (k < 0 || k <= maxchild)
            k = 0;
            //cout << k << "  k\n";

            unsigned long long p = (costbus*(j+1))+(tax*k);
           // cout<< k << " " << j << " " << p << endl;
               // cout << j << " "<< p << endl;
            if(p < sum)
                sum = p;
        }
        //cout << sum << endl;
        totalsum += sum;

    }
    cout << totalsum;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n,m, totalsum = 0;
    cin >> n >> m;
    for(int i = 0;i  <n; i++)
    {
        int t,T,tax,costbus;
        long long sum = 0;
        cin >> t >> T >> tax >> costbus;
        int maxchild = T-t;
       // cout << maxchild << " *\n";
        if(maxchild >= m)
        {
            totalsum += costbus;
            //cout << costbus << "   ((\n";
            continue;
        }
        sum = tax * m + costbus;
        //cout << sum << "  s"  << endl;
        for(int j = 1;j <= m;j++)
        {
            int k = m - maxchild*j ;
            if (k < 0 || k <= maxchild)
            k = 0;
            //cout << k << "  k\n";

            int p = (costbus*(j+1))+(tax*k);
           // cout<< k << " " << j << " " << p << endl;
               // cout << j << " "<< p << endl;
            if(p > sum)
                break;
            else
                sum = p;
        }
        //cout << sum << endl;
        totalsum += sum;

    }
    cout << totalsum;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int   main()
{
    int n,m;
    unsigned long long sum = 0;
    cin >> n >> m;
    while(n--)
    {
        long long  t,T,tax,cost;
        cin >> t >> T >> tax >> cost;

        long long  maxst = T-t;
        if(t+m <= T)
        {
        //cout << 1 << endl;
        sum += cost;
        }
        else if(maxst <= 0)
        {
         //    cout << 2 << endl;
            sum += tax*m + cost;
        }
        else
        {
            unsigned long long  maxsum = tax*m + cost;
            for(unsigned long long  i = 2; (i-1)*maxst <= m+maxst; i++)
            {
                 long long  posi = m - maxst*(i-1);
                if(posi <= maxst)
                    posi = 0;
                unsigned long long  a = i*cost + tax*(posi);

                if(a > maxsum)
                    break;
                maxsum = a;
            }
            //cout << maxsum << endl;
            sum += maxsum;
        }
    }
    cout << sum;
    return 0;
}


    #include <bits/stdc++.h>

    using namespace std;

    int main()
    {
        int n,m;
        unsigned long long  totalsum = 0;
        cin >> n >> m;
        for(int i = 0;i  <n; i++)
        {
            int t,T,tax,costbus;
            unsigned long long sum = 0;
            cin >> t >> T >> tax >> costbus;
            int maxchild = T-t;
           // cout << maxchild << " *\n";
            if(maxchild >= m)
            {
                totalsum += costbus;
                //cout << costbus << "   ((\n";
                continue;
            }
            else if(maxchild <= 0)
            {
                totalsum += tax * m + costbus;
                continue;
            }
            sum = tax * m + costbus;
            //cout << sum << "  s"  << endl;
            for(int j = 1;j*maxchild <= m+maxchild;j++)
            {
                int k = m - maxchild*j ;
                if (k < 0 || k <= maxchild)
                k = 0;
                //cout << k << "  k\n";

                unsigned long long p = (costbus*(j+1))+(tax*k);
               // cout<< k << " " << j << " " << p << endl;
                   // cout << j << " "<< p << endl;
                if(p < sum)
                    sum = p;
            }
            //cout << sum << endl;
            totalsum += sum;

        }
        cout << totalsum;

        return 0;
    }


#include <bits/stdc++.h>
using namespace std;
#define fast() ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lp(i, n) for(int i = 0; i < n; i++)
#define rlp(i, n) for(int i = n-1; i >= 0; i--)
#define loop(i, a, b) for(int i = a; i <= b; i++)
#define rloop(i, a, b) for(int i = a; i >= b; i--)
#define mem(a, val) memset(a, val, sizeof a);
#define all(v) v.begin(),v.end()
#define ll long long
#define ld long double
#define mp_ make_pair
#define pb push_back
#define sz(s) (int)s.size()
const int N = 1e4 + 4;
const int inf = 1e9+1;
const ll OO = 1e18;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
ll ans;
int main()
{
    ll n, m, t, T, x, cost;
    cin>> n >> m;
    lp(i, n){
        cin>> t >> T >> x >> cost;
        ans += cost;
        if(t + m <= T) continue;
        ll ch1 = OO, ch2 = OO;
        ch1 = m * x;
        if(t < T)
            ch2 = cost * ceil((double)m / (T - t)) - cost;
        ans += min(ch1, ch2);
    }
    cout<< ans;
    return 0;
}


#include<iostream>
#include<fstream>
#include<string>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<set>
#include<bitset>
#include <iomanip>
using namespace std;
int n,m;
vector<int> gr[201];

int tc, t, x, c;
int es()
{

	int c1=n*x+c;
if(t>=tc)
return c1;
int c2=((n/(tc-t)+n%(tc-t)!=0)*c);
if(c1>c2)
return c2;
else
return c1;

}
int main()
{

	cin >> m>>n;
	int an = 0;
	for (int i = 0; i < m; i++)
	{
		cin >> t >> tc >> x >> c;
		an += es();
	}
	cout << an;
	return 0;
}


#include<iostream>
#include<fstream>
#include<string>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<set>
#include<bitset>
#include <iomanip>
using namespace std;
int n,m;
vector<int> gr[201];

int tc, t, x, c;
int es()
{

	if (t + n <= tc)
		return c;
	int r = 0;
	int la = (tc - t) + (n % (tc - t) == 0 ? (tc - t) : n % (tc - t));
	int te = n - la;
	if ((te / (tc - t))*(c - (tc - t)*x) + c > la*x)
		return c + n*x;
		return  ((2 + te / (tc - t))*c);

}
int main()
{

	cin >> m>>n;
	int an = 0;
	for (int i = 0; i < m; i++)
	{
		cin >> t >> tc >> x >> c;
		an += es();
	}
	cout << an;
	return 0;
}


#include<iostream>
#include<fstream>
#include<string>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<set>
#include<bitset>
#include <iomanip>
using namespace std;
int n,m;
vector<int> gr[201];

long long tc, t, x, c;
long long es()
{

	if (t + n <= tc)
		return c;

	int r = 0;
	if (tc <= t)
	{

		return n*x+c;

	}
	int la = (tc - t) + (n % (tc - t) == 0 ? (tc - t) : n % (tc - t));
	int te = n - la;
	if ((te / (tc - t))*(c - (tc - t)*x) + c > la*x)
		return c + n*x;
		return  ((2 + te / (tc - t))*c);

}
int main()
{

	cin >> m>>n;
	long long an = 0;
	for (int i = 0; i < m; i++)
	{
		cin >> t >> tc >> x >> c;
		an += es();
	}
	cout << an;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

int main()
{
    ll n,m;
    cin>>n>>m;
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        ll t,s,x,c;
        cin>>t>>s>>x>>c;
        if(t>=s)
            ans+=c+x*m;
        else
        {
            ll d=s-t;
            if(d>=m)
                ans+=c;
            else
            {
                ll t=(m+d-1)/d;
                ans+=min({x*m+c,t*c,(t-1)*(c-d*x)+x*(d+m)});
            }
        }
    }
    cout<<ans;
}


#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
LL check(int t, int T, int x, int cost, int tot, int cnt)
{
	int p = T - t;
	if (1LL * cnt * p >= tot)
	{
		return cnt * cost;
	}
	return 1LL*cnt * cost + (p + tot - cnt * p) * 1LL * x;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	scanf("%d%d", &n, &m);
	LL ans = 0;
	while (n--)
	{
		int t, T, x, cost;
		scanf("%d%d%d%d", &t, &T, &x, &cost);
		if (t >= T)
		{
			ans += cost + 1LL * x * m;
			continue;
		}
		int o = max(1, m / (T - t));
		ans += min({ check(t,T,x,cost,m,1),check(t,T,x,cost,m,o),check(t,T,x,cost,m,o + 1) });
	}
	printf("%lld\n", ans);
	return 0;
}


#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
LL check(int t, int T, int x, int cost, int tot, int cnt)
{
	int p = T - t;
	if (1LL * cnt * p >= tot)
	{
		return 1LL*cnt * cost;
	}
	return 1LL*cnt * cost + (p + tot - cnt * p) * 1LL * x;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	scanf("%d%d", &n, &m);
	LL ans = 0;
	while (n--)
	{
		int t, T, x, cost;
		scanf("%d%d%d%d", &t, &T, &x, &cost);
		if (t >= T)
		{
			ans += cost + 1LL * x * m;
			continue;
		}
		int o = max(1, m / (T - t));
		ans += min({ check(t,T,x,cost,m,1),check(t,T,x,cost,m,o),check(t,T,x,cost,m,o + 1) });
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define MX 100005
using namespace std;

int t[MX], T[MX], x[MX], c[MX], n, m;

int32_t main(){
    //freopen("in.txt", "r", stdin);
    int i, j, ans, b, ex;
    cin >> n >> m;
    for(i=0;i<n;i++){
        cin >> t[i] >> T[i] >> x[i] >> c[i];
    }
    ans = 0;
    for(i=0;i<n;i++){
        if(t[i]>=T[i]){
            ans += m*x[i] + c[i];
            continue;
        }
        ex = (m/(T[i]-t[i]) + (bool)(m%(T[i]-t[i])))*c[i];
        b = m*x[i] + c[i];
        ans += min(ex, b);
    }
    cout << ans;
    return 0;
}


// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010],vis(100010,0),dis(100010,inf),par(100010,0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    ll n,m;
    cin>>n>>m;
    ll cost=0;
    f(i,n)
    {
        vector<ll> v(4);
        f(i,4)
        {
            cin>>v[i];
        }
        ll lo=0,hi=1<<30;
        while(hi-lo>1)
        {
            ll mid=(lo+hi)/2;
            ll cost1=0,cost2=0;
            if(v[0]>=v[1])
            {
                cost1+=mid*v[3]+m*v[2];
                cost2+=(mid+1)*v[3]+m*v[2];
            }
            else
            {
                ll num=v[1]-v[0];
                if(num*mid<m)
                {
                    ll temp=m;
                    temp=temp-(mid-1)*num;
                    cost1=cost1+mid*v[3]+temp*v[2];
                }
                else
                {
                    cost1=cost1+mid*v[3];
                }
                if(num*(mid+1)<m)
                {
                    ll temp=m;
                    temp=temp-(mid)*num;
                    cost2=cost2+(mid+1)*v[3]+temp*v[2];
                }
                else
                {
                    cost2=cost2+(mid+1)*v[3];
                }
            }
            if(cost1<=cost2)
            {
                hi=mid;
            }
            else
            {
                lo=mid;
            }
        }
        if(v[0]>=v[1])
        {
             cost=cost+hi*v[3]+m*v[2];
        }
        else
        {
            ll num=v[1]-v[0];
            if(num*hi<m)
            {
                ll temp=m;
                temp=temp-(hi-1)*num;
                cost=cost+hi*v[3]+temp*v[2];
            }
            else
            {
                cost=cost+hi*v[3];
            }
        }
    }
    cout<<cost<<endl;
}


// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010],vis(100010,0),dis(100010,inf),par(100010,0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    ll n,m;
    cin>>n>>m;
    ll cost=0;
    f(i,n)
    {
        vector<ll> v(4);
        f(i,4)
        {
            cin>>v[i];
        }
        if(v[0]>=v[1])
        {
            cost+=v[3]+m*v[2];
            continue;
        }
        ll lo=0,hi=1ll<<20;
        ll c=1ll<<60;
        while(hi-lo>1)
        {
            ll mid=(lo+hi)/2;
            ll cost1=0,cost2=0;
            ll num=v[1]-v[0];
            if(num*mid<m)
            {
                ll temp=m;
                temp=temp-(mid-1)*num;
                cost1=cost1+mid*v[3]+temp*v[2];
            }
            else
            {
                cost1=cost1+mid*v[3];
            }
            if(num*(mid+1)<m)
            {
                ll temp=m;
                temp=temp-(mid)*num;
                cost2=cost2+(mid+1)*v[3]+temp*v[2];
            }
            else
            {
                cost2=cost2+(mid+1)*v[3];
            }
            c=min(c,min(cost1,cost2));
            if(cost1<cost2)
            {
                hi=mid;
            }
            else
            {
                lo=mid;
            }
        }
        cost+=c;
    }
    cout<<cost<<endl;
}


// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010],vis(100010,0),dis(100010,inf),par(100010,0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    ll n,m;
    cin>>n>>m;
    ll cost=0;
    f(i,n)
    {
        vector<ll> v(4);
        f(i,4)
        {
            cin>>v[i];
        }
        ll lo=0,hi=1<<30;
        while(hi-lo>1)
        {
            ll mid=(lo+hi)/2;
            ll cost1=0,cost2=0;
            if(v[0]>v[1])
            {
                cost1+=mid*v[3]+m*v[2];
                cost2+=(mid+1)*v[3]+m*v[2];
            }
            else
            {
                ll num=v[1]-v[0];
                if(num*mid<m)
                {
                    ll temp=m;
                    temp=temp-(mid-1)*num;
                    cost1=cost1+mid*v[3]+temp*v[2];
                }
                else
                {
                    cost1=cost1+mid*v[3];
                }
                if(num*(mid+1)<m)
                {
                    ll temp=m;
                    temp=temp-(mid)*num;
                    cost2=cost2+(mid+1)*v[3]+temp*v[2];
                }
                else
                {
                    cost2=cost2+(mid+1)*v[3];
                }
            }
            if(cost1<=cost2)
            {
                hi=mid;
            }
            else
            {
                lo=mid;
            }
        }
        ll num=v[1]-v[0];
        if(num*(lo+1)<m)
        {
            ll temp=m;
            temp=temp-(lo)*num;
            cost=cost+(lo+1)*v[3]+temp*v[2];
        }
        else
        {
            cost=cost+(lo+1)*v[3];
        }
    }
    cout<<cost<<endl;
}


// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010],vis(100010,0),dis(100010,inf),par(100010,0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    ll n,m;
    cin>>n>>m;
    ll cost=0;
    f(i,n)
    {
        vector<ll> v(4);
        f(i,4)
        {
            cin>>v[i];
        }
        if(v[0]>=v[1])
        {
            cost+=v[3]+m*v[2];
            continue;
        }
        ll lo=0,hi=1<<30;
        ll c=1ll<<60;
        while(hi-lo>1)
        {
            ll mid=(lo+hi)/2;
            ll cost1=0,cost2=0;
            ll num=v[1]-v[0];
            if(num*mid<m)
            {
                ll temp=m;
                temp=temp-(mid-1)*num;
                cost1=cost1+mid*v[3]+temp*v[2];
            }
            else
            {
                cost1=cost1+mid*v[3];
            }
            if(num*(mid+1)<m)
            {
                ll temp=m;
                temp=temp-(mid)*num;
                cost2=cost2+(mid+1)*v[3]+temp*v[2];
            }
            else
            {
                cost2=cost2+(mid+1)*v[3];
            }
            c=min(c,min(cost1,cost2));
            if(cost1<=cost2)
            {
                hi=mid;
            }
            else
            {
                lo=mid;
            }
        }
        cost+=c;
    }
    cout<<cost<<endl;
}


// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010],vis(100010,0),dis(100010,inf),par(100010,0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    ll n,m;
    cin>>n>>m;
    ll cost=0;
    f(i,n)
    {
        vector<ll> v(4);
        f(i,4)
        {
            cin>>v[i];
        }
        ll cost1=1<<30,cost2=1<<30;
        if(v[0]+m<=v[1])
        {
            cost1=v[3];
        }
        else
        {
            cost1=v[3]+m*v[2];
        }
        if(v[0]<=v[1])
        {
            ll temp=v[1]-v[0];
            if(m%temp)
            {
                temp=m/temp+1;
            }
            else
            {
                temp=m/temp;
            }
            cost2=v[3]*temp;
        }
        cost+=min(cost1,cost2);
    }
    cout<<cost<<endl;
}


// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010],vis(100010,0),dis(100010,inf),par(100010,0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    ll n,m;
    cin>>n>>m;
    ll cost=0;
    f(i,n)
    {
        vector<ll> v(4);
        f(i,4)
        {
            cin>>v[i];
        }
        if(v[0]>=v[1])
        {
            cost+=v[3]+m*v[2];
            continue;
        }
        ll lo=0,hi=1<<30;
        while(hi-lo>1)
        {
            ll mid=(lo+hi)/2;
            ll cost1=0,cost2=0;
            ll num=v[1]-v[0];
            if(num*mid<m)
            {
                ll temp=m;
                temp=temp-(mid-1)*num;
                cost1=cost1+mid*v[3]+temp*v[2];
            }
            else
            {
                cost1=cost1+mid*v[3];
            }
            if(num*(mid+1)<m)
            {
                ll temp=m;
                temp=temp-(mid)*num;
                cost2=cost2+(mid+1)*v[3]+temp*v[2];
            }
            else
            {
                cost2=cost2+(mid+1)*v[3];
            }
            if(cost1<=cost2)
            {
                hi=mid;
            }
            else
            {
                lo=mid;
            }
        }
        ll num=v[1]-v[0];
        if(num*hi<m)
        {
            ll temp=m;
            temp=temp-(hi-1)*num;
            cost=cost+hi*v[3]+temp*v[2];
        }
        else
        {
            cost=cost+hi*v[3];
        }
    }
    cout<<cost<<endl;
}


// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010],vis(100010,0),dis(100010,inf),par(100010,0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    ll n,m;
    cin>>n>>m;
    ll cost=0;
    f(i,n)
    {
        vector<ll> v(4);
        f(i,4)
        {
            cin>>v[i];
        }
        ll lo=0,hi=1<<30;
        while(hi-lo>1)
        {
            ll mid=(lo+hi)/2;
            ll cost1=0,cost2=0;
            if(v[0]>=v[1])
            {
                cost1+=mid*v[3]+m*v[2];
                cost2+=(mid+1)*v[3]+m*v[2];
            }
            else
            {
                ll num=v[1]-v[0];
                if(num*mid<m)
                {
                    ll temp=m;
                    temp=temp-(mid-1)*num;
                    cost1=cost1+mid*v[3]+temp*v[2];
                }
                else
                {
                    cost1=cost1+mid*v[3];
                }
                if(num*(mid+1)<m)
                {
                    ll temp=m;
                    temp=temp-(mid)*num;
                    cost2=cost2+(mid+1)*v[3]+temp*v[2];
                }
                else
                {
                    cost2=cost2+(mid+1)*v[3];
                }
            }
            if(cost1<=cost2)
            {
                hi=mid;
            }
            else
            {
                lo=mid;
            }
        }
        ll num=v[1]-v[0];
        if(num*hi<m)
        {
            ll temp=m;
            temp=temp-(hi-1)*num;
            cost=cost+hi*v[3]+temp*v[2];
        }
        else
        {
            cost=cost+hi*v[3];
        }
    }
    cout<<cost<<endl;
}


// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010],vis(100010,0),dis(100010,inf),par(100010,0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    ll n,m;
    cin>>n>>m;
    ll cost=0;
    f(i,n)
    {
        vector<ll> v(4);
        f(i,4)
        {
            cin>>v[i];
        }
        ll cost1=1<<30,cost2=1<<30;
        if(v[0]+m<=v[1])
        {
            cost1=v[3];
        }
        else
        {
            cost1=v[3]+m*v[2];
        }
        if(v[0]<v[1])
        {
            ll temp=v[1]-v[0];
            if(m%temp)
            {
                temp=m/temp+1;
            }
            else
            {
                temp=m/temp;
            }
            cost2=v[3]*temp;
        }
        cost+=min(cost1,cost2);
    }
    cout<<cost<<endl;
}


// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010],vis(100010,0),dis(100010,inf),par(100010,0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    ll n,m;
    cin>>n>>m;
    ll cost=0;
    f(i,n)
    {
        vector<ll> v(4);
        f(i,4)
        {
            cin>>v[i];
        }
        ll cost1=1ll<<60,cost2=1ll<<60;
        if(v[0]+m<=v[1])
        {
            cost1=v[3];
        }
        else
        {
            cost1=v[3]+m*v[2];
        }
        if(v[0]<=v[1])
        {
            ll temp=v[1]-v[0];
            if(m%temp)
            {
                temp=m/temp+1;
            }
            else
            {
                temp=m/temp;
            }
            cost2=v[3]*temp;
        }
        cost+=min(cost1,cost2);
    }
    cout<<cost<<endl;
}


// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010],vis(100010,0),dis(100010,inf),par(100010,0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    ll n,m;
    cin>>n>>m;
    ll cost=0;
    f(i,n)
    {
        vector<ll> v(4);
        f(i,4)
        {
            cin>>v[i];
        }
        ll cost1=1ll<<30,cost2=1ll<<30;
        if(v[0]+m<=v[1])
        {
            cost1=v[3];
        }
        else
        {
            cost1=v[3]+m*v[2];
        }
        if(v[0]<v[1])
        {
            ll temp=v[1]-v[0];
            if(m%temp)
            {
                temp=m/temp+1;
            }
            else
            {
                temp=m/temp;
            }
            cost2=v[3]*temp;
        }
        cost+=min(cost1,cost2);
    }
    cout<<cost<<endl;
}


// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010],vis(100010,0),dis(100010,inf),par(100010,0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    ll n,m;
    cin>>n>>m;
    ll cost=0;
    f(i,n)
    {
        vector<ll> v(4);
        f(i,4)
        {
            cin>>v[i];
        }
        if(v[0]>=v[1])
        {
            cost+=v[3]+m*v[2];
            continue;
        }
        ll lo=0,hi=1ll<<20;
        ll c=1ll<<60;
        while(hi-lo>1)
        {
            ll mid=(lo+hi)/2;
            ll cost1=0,cost2=0;
            ll num=v[1]-v[0];
            if(num*mid<m)
            {
                ll temp=m;
                temp=temp-(mid-1)*num;
                cost1=cost1+mid*v[3]+temp*v[2];
            }
            else
            {
                cost1=cost1+mid*v[3];
            }
            if(num*(mid+1)<m)
            {
                ll temp=m;
                temp=temp-(mid)*num;
                cost2=cost2+(mid+1)*v[3]+temp*v[2];
            }
            else
            {
                cost2=cost2+(mid+1)*v[3];
            }
            c=min(c,min(cost1,cost2));
            if(cost1<=cost2)
            {
                hi=mid;
            }
            else
            {
                lo=mid;
            }
        }
        cost+=c;
    }
    cout<<cost<<endl;
}


// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010],vis(100010,0),dis(100010,inf),par(100010,0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    ll n,m;
    cin>>n>>m;
    ll cost=0;
    f(i,n)
    {
        vector<ll> v(4);
        f(i,4)
        {
            cin>>v[i];
        }
        if(v[0]>=v[1])
        {
            cost+=v[3]+m*v[2];
            continue;
        }
        ll lo=0,hi=1ll<<60;
        ll c=1ll<<60;
        while(hi-lo>1)
        {
            ll mid=(lo+hi)/2;
            ll cost1=0,cost2=0;
            ll num=v[1]-v[0];
            if(num*mid<m)
            {
                ll temp=m;
                temp=temp-(mid-1)*num;
                cost1=cost1+mid*v[3]+temp*v[2];
            }
            else
            {
                cost1=cost1+mid*v[3];
            }
            if(num*(mid+1)<m)
            {
                ll temp=m;
                temp=temp-(mid)*num;
                cost2=cost2+(mid+1)*v[3]+temp*v[2];
            }
            else
            {
                cost2=cost2+(mid+1)*v[3];
            }
            c=min(c,min(cost1,cost2));
            if(cost1<=cost2)
            {
                hi=mid;
            }
            else
            {
                lo=mid;
            }
        }
        cost+=c;
    }
    cout<<cost<<endl;
}


// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010],vis(100010,0),dis(100010,inf),par(100010,0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    ll n,m;
    cin>>n>>m;
    ll cost=0;
    f(i,n)
    {
        vector<ll> v(4);
        f(i,4)
        {
            cin>>v[i];
        }
        ll cost1=1ll<<60,cost2=1ll<<60;
        if(v[0]+m<=v[1])
        {
            cost1=v[3];
        }
        else
        {
            cost1=v[3]+m*v[2];
        }
        if(v[0]<v[1])
        {
            ll temp=v[1]-v[0];
            if(m%temp)
            {
                temp=m/temp+1;
            }
            else
            {
                temp=m/temp;
            }
            cost2=v[3]*temp;
        }
        cost+=min(cost1,cost2);
    }
    cout<<cost<<endl;
}


//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}

ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}

int main(){

    // ios_base::sync_with_stdio(0);

    int n, m;
    scanf("%d%d", &n, &m);
    ll ans = 0;
    while(n--){

        ll t, T, x, cost;
        scanf("%lld%lld%lld%lld", &t, &T, &x, &cost);

        if(t >= T){
            ans += cost + m*x;
        }
        else{
            T -= t;
// cout<<T<<" "<<x<<" "<<cost<<endl;
            if(m <= T){
                ans += cost;
            }
            else if(cost <= T*x){
                //use as many buses as possible
                ll buses = m / T;
                ll rem = m % T;
                ans += buses * cost;
                if(rem > 0)
                    ans += min(cost, (T+rem)*x);
            }
            else{
                //using single bus
                ans += m*x + cost;
            }
        }
// cout<<ans<<endl;
    }

    printf("%lld\n", ans);
    return 0;
}


//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}

ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}

int main(){

    // ios_base::sync_with_stdio(0);

    int n, m;
    scanf("%d%d", &n, &m);
    ll ans = 0;
// n=1;
    while(n--){

        ll t, T, x, cost;
        scanf("%lld%lld%lld%lld", &t, &T, &x, &cost);

        T -= t;
        if(T <= 0){
            ans += cost + m*x;
        }
        else{
// cout<<T<<" "<<x<<" "<<cost<<endl;
            if(m <= T){
                ans += cost;
                continue;
            }

            //use single bus
            ll temp = m*x + cost;

            //use floor(m/T) buses and keep extra children in some bus
            ll buses = m / T;
            ll rem = m % T;
            if(rem > 0)
                temp = min(temp, buses*cost+(T+rem)*x);
            else
                temp = min(temp, buses*cost);

// cout<<T<<endl;
            //use ceil(m/T) buses
            buses = (m+T-1) / T;
            temp = min(temp, buses*cost);

            ans += temp;
        }
// cout<<ans<<endl;
    }

    printf("%lld\n", ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <queue>
#include <unordered_set>
using namespace std;

int n, m;
long long ans = 0;

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		long long t, T, x, cost;
		cin >> t >> T >> x >> cost;
		long long currAns = cost + (t + m > T) * m * x;
		if (t < T) {
			int opt = T - t;
			int buses = (m + opt - 1) / opt;
			currAns = min(currAns, cost * buses);
		}
		ans += currAns;
	}
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define trace(x) cerr<<#x<<":"<<x<<'\n';
#define trace2(a,n) { cerr<<#a<<" = "; for(int i=0; i<n; ++i){ cerr << a[i] << ' '; } ; cerr <<'\n'; }

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  ll m;
  cin>>n>>m;
  ll ans = 0;
  for(int i=0; i<n; ++i){
    ll t,T,x,cost;
    cin>>t>>T>>x>>cost;
    ll curr_ans;
    ll diff = T-t;
    if( diff <= 0 ){
      curr_ans = cost + m * x;
    }else{
      ll bus = m/diff + ((m % diff == 0 ) ? 0 : 1);
      curr_ans = min( cost + m * x , bus * cost );
    }
    ans += curr_ans;
  }
  cout<<ans<<'\n';

  #ifdef LOL
      cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
  return 0;
}


#include <iostream>
#include <vector>
#define fastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long int

using namespace std;

ll x[100010], T[100010], t[100010], cost[100010];

int main()
{
	ll n, m;
	cin >> n >> m;
	for(int i = 0 ; i < n ; i++){
		cin >> t[i] >> T[i] >> x[i] >> cost[i];
	}
	ll res = 0;
	for (int i = 0; i < n; i++){
		ll aux1 = cost[i], aux2;
		if(t[i] + m > T[i]) aux1 += x[i]*m;
		if(t[i] >= T[i]){
			res += aux1;
			continue;
		}
		aux2 = (m + T[i] - t[i] - 1)/(T[i] - t[i]);
		aux2 *= cost[i];
		res += min(aux1, aux2);
	}
	cout << res;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long n,m,res=0;
   cin>>n>>m;
   while(n--)
   {
       long long t1,t2,x,c;
       cin>>t1>>t2>>x>>c;
       long long cost = m*x*(t1+m >t2) +c;
       if(t1<t2)
       {
           long long cost2=c*((m-1)/(t2-t1) + 1);
           cost=min(cost,cost2);
       }
       res+=cost;
   }
   cout<<res<<endl;
}


#include <bits/stdc++.h>

    #define ll long long
                                                 #define scanint1(a) scanf("%d",&a)
                                                 #define scanint2(a,b) scanf("%d %d",&a,&b)
                                                 #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
                                                 #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
                                                 #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
                                                 #define scanint6(a,b,c,d,e,f) scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)
                                                 #define scanlong1(a) scanf("%ld",&a)
                                                 #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
                                                 #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
                                                 #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
                                                 #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
                                                 #define scanll1(a) scanf("%lld",&a)
                                                 #define scanll2(a,b) scanf("%lld %lld",&a,&b)
                                                 #define scanll3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
                                                 #define scanll4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
                                                 #define scanll5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
                                                 #define read  freopen("in.txt","r",stdin);
                                                 #define write freopen("out.txt","w",stdout);
                                                 #define MAXN   10000005
                                                  //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
                                                  //Convert from char int to int char-48
                                                 //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
                                                 //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
                                                // int dx[] ={-1,0,0,1};
                                                // int dy[] ={0,1,-1,0};
                                                 //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }
                                                /*for(int k = 0 ; k<4;k++){
                                                                    int nx = dx[k] + x;
                                                                    int ny = dy[k]+y;
                                                                     if(!vis[nx][ny] &&valid(nx,ny)){
                                                                        vis[nx][ny] = vis[x][y] + 1;
                                                                        q.push({nx,ny});
                                                                    }
                                                                }  */

                                                        using namespace std;

                                                            int main()

                                                    {

                                                            int n,k;
                                                            scanint2(n,k);
                                                            ll ans=0;
                                                            for(int i=0;i<n;i++)
                                                            {
                                                                int t,T,x,c;
                                                                scanint4(t,T,x,c);

                                                                if(t+k<=T)
                                                                    ans+=c;
                                                                else if(T<=t)
                                                                    ans+=c+x*k;
                                                                else
                                                                {
                                                                    ll temp1=c+k*x;
                                                                    ll temp2=k/abs(T-t);
                                                                    temp2=temp2*c;

                                                                    if(k%abs(T-t))
                                                                    temp2+=x*(k%abs(T-t)+ k/abs(T-t));
                                                                    ans+=min(temp1,temp2);
                                                                }

                                                            }

                                                            cout<<ans<<endl;
                                                            return 0;

                                                    }


#include <bits/stdc++.h>

    #define ll long long
                                                 #define scanint1(a) scanf("%d",&a)
                                                 #define scanint2(a,b) scanf("%d %d",&a,&b)
                                                 #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
                                                 #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
                                                 #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
                                                 #define scanint6(a,b,c,d,e,f) scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)
                                                 #define scanlong1(a) scanf("%ld",&a)
                                                 #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
                                                 #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
                                                 #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
                                                 #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
                                                 #define scanll1(a) scanf("%lld",&a)
                                                 #define scanll2(a,b) scanf("%lld %lld",&a,&b)
                                                 #define scanll3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
                                                 #define scanll4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
                                                 #define scanll5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
                                                 #define read  freopen("in.txt","r",stdin);
                                                 #define write freopen("out.txt","w",stdout);
                                                 #define MAXN   10000005
                                                  //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
                                                  //Convert from char int to int char-48
                                                 //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
                                                 //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
                                                // int dx[] ={-1,0,0,1};
                                                // int dy[] ={0,1,-1,0};
                                                 //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }
                                                /*for(int k = 0 ; k<4;k++){
                                                                    int nx = dx[k] + x;
                                                                    int ny = dy[k]+y;
                                                                     if(!vis[nx][ny] &&valid(nx,ny)){
                                                                        vis[nx][ny] = vis[x][y] + 1;
                                                                        q.push({nx,ny});
                                                                    }
                                                                }  */

                                                        using namespace std;

                                                            int main()

                                                    {

                                                            int n,k;
                                                            scanint2(n,k);
                                                            ll ans=0;
                                                            for(int i=0;i<n;i++)
                                                            {
                                                                int t,T,x,c;
                                                                scanint4(t,T,x,c);

                                                                if(t+k<=T)
                                                                    ans+=c;
                                                                else if(T<=t)
                                                                 ans+=c+x*k;
                                                                else
                                                                {
                                                                    ll temp1=c+k*x;
                                                                    ll temp2=k/abs(T-t);
                                                                    ll temp3=c*(temp2+1);
                                                                    temp2*=c;

                                                                    if(k%abs(T-t))
                                                                    temp2+=x*(k%abs(T-t)+k/abs(T-t));
                                                                    ans+=min(temp1,min(temp2,temp3));
                                                                }

                                                            }

                                                            cout<<ans<<endl;
                                                            return 0;

                                                    }


#include <bits/stdc++.h>

    #define ll long long
                                                 #define scanint1(a) scanf("%d",&a)
                                                 #define scanint2(a,b) scanf("%d %d",&a,&b)
                                                 #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
                                                 #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
                                                 #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
                                                 #define scanint6(a,b,c,d,e,f) scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)
                                                 #define scanlong1(a) scanf("%ld",&a)
                                                 #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
                                                 #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
                                                 #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
                                                 #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
                                                 #define scanll1(a) scanf("%lld",&a)
                                                 #define scanll2(a,b) scanf("%lld %lld",&a,&b)
                                                 #define scanll3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
                                                 #define scanll4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
                                                 #define scanll5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
                                                 #define read  freopen("in.txt","r",stdin);
                                                 #define write freopen("out.txt","w",stdout);
                                                 #define MAXN   10000005
                                                  //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
                                                  //Convert from char int to int char-48
                                                 //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
                                                 //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
                                                // int dx[] ={-1,0,0,1};
                                                // int dy[] ={0,1,-1,0};
                                                 //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }
                                                /*for(int k = 0 ; k<4;k++){
                                                                    int nx = dx[k] + x;
                                                                    int ny = dy[k]+y;
                                                                     if(!vis[nx][ny] &&valid(nx,ny)){
                                                                        vis[nx][ny] = vis[x][y] + 1;
                                                                        q.push({nx,ny});
                                                                    }
                                                                }  */

                                                        using namespace std;

                                                            int main()

                                                    {

                                                            int n,k;
                                                            scanint2(n,k);
                                                            ll ans=0;
                                                            for(int i=0;i<n;i++)
                                                            {
                                                                int t,T,x,c;
                                                                scanint4(t,T,x,c);

                                                                if(t+k<=T ||T<=t)
                                                                    ans+=c;
                                                                else
                                                                {
                                                                    ll temp1=c+k*x;
                                                                    ll temp2=k/abs(T-t);
                                                                    temp2=temp2*c;

                                                                    if(k%abs(T-t))
                                                                    temp2+=x*(k%abs(T-t)+ k/abs(T-t));
                                                                    ans+=min(temp1,temp2);
                                                                }

                                                            }

                                                            cout<<ans<<endl;
                                                            return 0;

                                                    }


#include <bits/stdc++.h>

    #define ll long long
                                                 #define scanint1(a) scanf("%d",&a)
                                                 #define scanint2(a,b) scanf("%d %d",&a,&b)
                                                 #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
                                                 #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
                                                 #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
                                                 #define scanint6(a,b,c,d,e,f) scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)
                                                 #define scanlong1(a) scanf("%ld",&a)
                                                 #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
                                                 #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
                                                 #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
                                                 #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
                                                 #define scanll1(a) scanf("%lld",&a)
                                                 #define scanll2(a,b) scanf("%lld %lld",&a,&b)
                                                 #define scanll3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
                                                 #define scanll4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
                                                 #define scanll5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
                                                 #define read  freopen("in.txt","r",stdin);
                                                 #define write freopen("out.txt","w",stdout);
                                                 #define MAXN   10000005
                                                  //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
                                                  //Convert from char int to int char-48
                                                 //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
                                                 //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
                                                // int dx[] ={-1,0,0,1};
                                                // int dy[] ={0,1,-1,0};
                                                 //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }
                                                /*for(int k = 0 ; k<4;k++){
                                                                    int nx = dx[k] + x;
                                                                    int ny = dy[k]+y;
                                                                     if(!vis[nx][ny] &&valid(nx,ny)){
                                                                        vis[nx][ny] = vis[x][y] + 1;
                                                                        q.push({nx,ny});
                                                                    }
                                                                }  */

                                                        using namespace std;

                                                            int main()

                                                    {

                                                            ll n,k;
                                                            scanll2(n,k);
                                                            ll ans=0;
                                                            for(int i=0;i<n;i++)
                                                            {
                                                                ll t,T,x,c;
                                                                scanll4(t,T,x,c);

                                                                if(t+k<=T)
                                                                    ans+=c;
                                                                else if(T<=t)
                                                                 ans+=c+x*k;
                                                                else
                                                                {
                                                                    ll temp1=c+k*x;
                                                                    ll temp2=k/abs(T-t);
                                                                    ll temp3=c*((k+(T-t)-1)/abs(T-t));
                                                                    temp2*=c;

                                                                    if(k%abs(T-t))
                                                                    temp2+=x*(k%abs(T-t)+k/abs(T-t));
                                                                    ans+=min(temp1,min(temp2,temp3));
                                                                }

                                                            }

                                                            cout<<ans<<endl;
                                                            return 0;

                                                    }


#include <bits/stdc++.h>

    #define ll long long
                                                 #define scanint1(a) scanf("%d",&a)
                                                 #define scanint2(a,b) scanf("%d %d",&a,&b)
                                                 #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
                                                 #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
                                                 #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
                                                 #define scanint6(a,b,c,d,e,f) scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)
                                                 #define scanlong1(a) scanf("%ld",&a)
                                                 #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
                                                 #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
                                                 #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
                                                 #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
                                                 #define scanll1(a) scanf("%lld",&a)
                                                 #define scanll2(a,b) scanf("%lld %lld",&a,&b)
                                                 #define scanll3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
                                                 #define scanll4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
                                                 #define scanll5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
                                                 #define read  freopen("in.txt","r",stdin);
                                                 #define write freopen("out.txt","w",stdout);
                                                 #define MAXN   10000005
                                                  //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
                                                  //Convert from char int to int char-48
                                                 //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
                                                 //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
                                                // int dx[] ={-1,0,0,1};
                                                // int dy[] ={0,1,-1,0};
                                                 //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }
                                                /*for(int k = 0 ; k<4;k++){
                                                                    int nx = dx[k] + x;
                                                                    int ny = dy[k]+y;
                                                                     if(!vis[nx][ny] &&valid(nx,ny)){
                                                                        vis[nx][ny] = vis[x][y] + 1;
                                                                        q.push({nx,ny});
                                                                    }
                                                                }  */

                                                        using namespace std;

                                                            int main()

                                                    {

                                                            ll n,k;
                                                            scanll2(n,k);
                                                            ll ans=0;
                                                            for(int i=0;i<n;i++)
                                                            {
                                                                ll t,T,x,c;
                                                                scanll4(t,T,x,c);

                                                                if(t+k<=T)
                                                                    ans+=c;
                                                                else if(T<=t)
                                                                 ans+=c+x*k;
                                                                else
                                                                {
                                                                    ll temp1=c+k*x;
                                                                    ll temp2=k/abs(T-t);
                                                                    ll temp3=c*((k+T-t-1)/abs(T-t));
                                                                    temp2*=c;

                                                                    if(k%abs(T-t))
                                                                    temp2+=x*(k%abs(T-t)+k/abs(T-t));
                                                                    ans+=min(temp1,temp3);
                                                                }

                                                            }

                                                            cout<<ans<<endl;
                                                            return 0;

                                                    }


#include <bits/stdc++.h>

    #define ll long long
                                                 #define scanint1(a) scanf("%d",&a)
                                                 #define scanint2(a,b) scanf("%d %d",&a,&b)
                                                 #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
                                                 #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
                                                 #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
                                                 #define scanint6(a,b,c,d,e,f) scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)
                                                 #define scanlong1(a) scanf("%ld",&a)
                                                 #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
                                                 #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
                                                 #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
                                                 #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
                                                 #define scanll1(a) scanf("%lld",&a)
                                                 #define scanll2(a,b) scanf("%lld %lld",&a,&b)
                                                 #define scanll3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
                                                 #define scanll4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
                                                 #define scanll5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
                                                 #define read  freopen("in.txt","r",stdin);
                                                 #define write freopen("out.txt","w",stdout);
                                                 #define MAXN   10000005
                                                  //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
                                                  //Convert from char int to int char-48
                                                 //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
                                                 //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
                                                // int dx[] ={-1,0,0,1};
                                                // int dy[] ={0,1,-1,0};
                                                 //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }
                                                /*for(int k = 0 ; k<4;k++){
                                                                    int nx = dx[k] + x;
                                                                    int ny = dy[k]+y;
                                                                     if(!vis[nx][ny] &&valid(nx,ny)){
                                                                        vis[nx][ny] = vis[x][y] + 1;
                                                                        q.push({nx,ny});
                                                                    }
                                                                }  */

                                                        using namespace std;

                                                            int main()

                                                    {

                                                            ll n,k;
                                                            scanll2(n,k);
                                                            ll ans=0;
                                                            for(int i=0;i<n;i++)
                                                            {
                                                                ll t,T,x,c;
                                                                scanll4(t,T,x,c);

                                                                if(t+k<=T)
                                                                    ans+=c;
                                                                else if(T<=t)
                                                                 ans+=c+x*k;
                                                                else
                                                                {
                                                                    ll temp1=c+k*x;
                                                                    ll temp2=k/abs(T-t);
                                                                    ll temp3=c*(temp2+1);
                                                                    temp2*=c;

                                                                    if(k%abs(T-t))
                                                                    temp2+=x*(k%abs(T-t)+k/abs(T-t));
                                                                    ans+=min(temp1,min(temp2,temp3));
                                                                }

                                                            }

                                                            cout<<ans<<endl;
                                                            return 0;

                                                    }


#include <bits/stdc++.h>
using namespace std;
#define f(i,n) for (int i = 0;i < n; i++)
#define mul(costi, Ti, ti, q, xi, mid) (costi + Ti - ti) * q - xi * mid

typedef long long ll;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	ll n, m; cin >> n >> m;
	ll sum = 0;
	f(i,n) {
	    ll t, T, x, cost; cin >> t >> T >> x >> cost;
	    if (t + m <= T) sum += cost;
	    else {
	        ll ans = 0;
	        if (cost >= x * (T-t)) ans = (cost + x * m);
	        else ans = (cost - x * (T-t)) * (ll)floor((cost + x*m) * 1.0 / (x * (T-t) - cost))
	             + cost + x * m;
	        ans = min(ans, cost * (ll)ceil(m*1.0/(T-t)));
	        sum += ans;
	    }
	}
	cout << sum << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define f(i,n) for (int i = 0;i < n; i++)
#define mul(costi, Ti, ti, q, xi, mid) (costi + Ti - ti) * q - xi * mid

typedef long long ll;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	ll n, m; cin >> n >> m;
	ll sum = 0;
	f(i,n) {
	    ll t, T, x, cost; cin >> t >> T >> x >> cost;
	    if (t + m <= T) sum += cost;
	    else {
	        if (cost >= x * (T-t)) sum += (cost + x * m);
	        else sum += cost * (ll)ceil(m*1.0/(T-t));
	    }
	}
	cout << sum << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define f(i,n) for (int i = 0;i < n; i++)
typedef long long ll;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	ll n, m; cin >> n >> m;
	ll sum = 0;
	f(i,n) {
	    ll t, T, x, cost; cin >> t >> T >> x >> cost;
	    if (T <= t) sum += (cost + x * m);
	    else {
	        sum += min(cost + x * m, cost * (ll)ceil(m*1.0/(T-t)));
	    }
	}
	cout << sum << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define f(i,n) for (int i = 0;i < n; i++)
#define mul(costi, Ti, ti, q, xi, mid) (costi + Ti - ti) * q - xi * mid

typedef long long ll;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	ll n, m; cin >> n >> m;
	ll sum = 0;
	f(i,n) {
	    ll t, T, x, cost; cin >> t >> T >> x >> cost;
	    if (t + m <= T) sum += cost;
	    else {
	        ll ans = 0;
	        if (cost >= x * (T-t)) ans = (cost + x * m);
	        else {
	            ans = (cost - x * (T-t)) * (ll)floor((cost + x*m) * 1.0 / (x * (T-t) - cost))
	             + cost + x * m;
	            ans = min(ans, cost * (ll)ceil(m*1.0/(T-t)));
	        }
	        sum += ans;
	    }
	}
	cout << sum << endl;
	return 0;
}