#include <bits/stdc++.h>
 
#define lowbit(x) ((x) & (-x))
using namespace std;
 
typedef long long LL;
 
const int N = 200005;
 
int n, e;
int a[N], b[N], c[N], d[N * 4];
LL m, f[N * 4];
 
void init() {
    memset(f, 0, sizeof(f));
}
 
void add(int p, int val) {
    for (; p < e; p += lowbit(p)) f[p] += val;
}
 
LL cal(int p) {
    LL ans = 0;
    for (; p > 0; p -= lowbit(p)) ans += f[p];
    return ans;
}
 
void gao() {
    e = 0;
    d[e++] = 0;
    for (int i = 0; i < n; i++) {
        d[e++] = a[i], d[e++] = a[i] + 1;
        d[e++] = b[i], d[e++] = b[i] + 1;
    }
    sort(d, d + e);
    e = unique(d, d + e) - d;
    for (int i = 0; i < n; i++) {
        a[i] = lower_bound(d, d + e, a[i]) - d;
        b[i] = lower_bound(d, d + e, b[i]) - d;
        // printf("l= %d, r= %d, c= %d\n", a[i], b[i], c[i]);
    }
 
    init();
    for (int i = 0; i < n; i++) {
        add(a[i], c[i]);
        add(b[i] + 1, -c[i]);
    }
 
    LL ans = 0;
    for (int i = 1; i < e - 1; i++) {
        LL tmp = cal(i);
        // printf("i= %d %d %lld %lld\n", i, d[i], tmp, tmp * (d[i + 1] - d[i]));
        ans += min(m, tmp) * (d[i + 1] - d[i]);
    }
    cout << ans << '\n';
}
 
 
inline bool scan_d(int &num)  
{
        char in;bool IsN=false;
        in=getchar();
        if(in==EOF) return false;
        while(in!='-'&&(in<'0'||in>'9')) in=getchar();
        if(in=='-'){ IsN=true;num=0;}
        else num=in-'0';
        while(in=getchar(),in>='0'&&in<='9'){
                num*=10,num+=in-'0';
        }
        if(IsN) num=-num;
        return true;
}
 
int main() {
    scan_d(n);
    scanf("%lld", &m);
        for (int i = 0; i < n; i++) scan_d(a[i]), scan_d(b[i]), scan_d(c[i]);
        gao();
    return 0;
}
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;

#define endl '\n'
#define int long long int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define revrep(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;


ostream &operator<<( ostream &output, const pii &p ) { output << p.first << " " << p.second;return output; }
istream &operator>>( istream &input, pii &p ) { input >> p.first >> p.second;return input; }
template<typename T>
void inline println(vector<T> args){ for(T i: args)cout<<i<<" ";cout<<endl; }
void amax(int& a, int b) { a = max(a, b); }
void amin(int& a, int b) { a = min(a, b); }

const string YES = "Yes";
const string NO = "No";
int INF = 1e18;
int MOD = 998244353;


void solve()
{
    int a, b, x, y; cin>>a>>b>>x>>y;
    int dp[2][101];
    rep(i, 0, 2) rep(j, 0, 101) dp[i][j] = INF;
    set<pair<int, pii>> q;
    dp[0][a] = 0;
    q.insert({0, {0, a}});
    while(q.size()) {
        auto front = *q.begin();
        auto cor = front.second;
        q.erase(q.begin());
        vii nxt;
        int other = 1-cor.first;
        nxt.pb({cor.first, cor.second+1});
        nxt.pb({cor.first, cor.second-1});
        nxt.pb({other, cor.second});
        if(other == 0) nxt.pb({other, cor.second+1});
        else nxt.pb({other, cor.second-1});
        for(auto pr: nxt) {
            if(pr.second > 100) continue;
            if(pr.second < 0) continue;
            int dd = (pr.first == cor.first ? y:x);
            int dist = dd+dp[cor.first][cor.second];
            if(dp[pr.first][pr.second] > dist) {
                auto key = q.find({dp[pr.first][pr.second], pr});
                if(key != q.end()) q.erase(key);
                q.insert({dist, pr});
                dp[pr.first][pr.second] = dist;
            }
        }
    }
    cout<<dp[1][b]<<endl;
}

signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    rep(i, 0, t)
    {   
        solve();
    }
    return 0;
}