#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll x[n], y[n];
    rep(i, n) cin >> x[i] >> y[i];
    ll ans = 0;
    rep(i, n){
        for(int j = i + 1; j < n; j ++){
            ll dy = abs(y[j] - y[i]), dx = abs(x[j] - x[i]);
            if(dy <= dx) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF = 1e18;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1;} return 0;}
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0;}
// ここを消す
// #define DEBUG
#ifdef DEBUG
inline void debug_print() { cerr << endl; }
template <typename T1, typename... T2> void debug_print(const T1 a, const T2 &... b) { cerr << a << ' '; debug_print(b...);}
#define debug(...) cerr << __LINE__ << ':' << ' ' << '[' << #__VA_ARGS__ << ']' << '=' << ' ' , debug_print(__VA_ARGS__);
#else
#define debug(...) true
#endif

inline void print() { cout << endl; }
template <typename T1, typename... T2> void print(const T1 a, const T2 &... b) { cout << a << ' '; print(b...); }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ',' << ' ' << p.second << ')'; return os; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto e : v) os << e << ' '; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto e : v) os << e << ' ';  return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto e : mp) os << e << ' '; return os; }

/* compress
    X を座標圧縮して書き換える（副作用）
    返り値: ソート済みの値
    計算量: O(n log n)
*/
template <typename T>
vector<T> compress(vector<T> &X) {
    // ソートした結果を vals に
    vector<T> vals = X;
    sort(vals.begin(), vals.end());
    // 隣り合う重複を削除(unique), 末端のゴミを削除(erase)
    vals.erase(unique(vals.begin(), vals.end()), vals.end());
    // 各要素ごとに二分探索で位置を求める
    for (int i = 0; i < (int)X.size(); i++) {
        X[i] = lower_bound(vals.begin(), vals.end(), X[i]) - vals.begin();
    }
    return vals;
}

/////////////////////////////////////////
// 与えられた数列から、大小関係だけを抽出したい
/////////////////////////////////////////

int main() {
    ll n, cost;
    cin >> n >> cost;
    vector<ll> p(n*2+1, 0), q(n*2+1, 0), a(n), b(n), c(n), d(n*2), day(n*2);
    vector<pair<ll,ll> > e(n*2);
    rep(i, n) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; 
        d[i] = a[i];
        d[i + n] = b[i];
        e[i] = {a[i], i};
        e[i+n] = {b[i], i + n};
    }

    sort(e.begin(), e.end());

    debug(e);

    int dayi = 0;
    day[0] = e[0].first;

    rep(i, n * 2) {
        if (e[i].first != day[dayi]) {
            dayi++;
            day[dayi] = e[i].first;
        }
        debug(dayi);
        if (e[i].second < n) {
            p[dayi] += c[e[i].second];
        } else {
            p[dayi] -= c[e[i].second - n];
        }
    }
    debug(p);
    debug(day);
    rep(i, dayi + 2) {
        if (i != 0) q[i] = q[i-1] + p[i];
        else q[i] = p[i];
    }
    debug(q);
    ll ans = 0;
    rep(i, dayi + 1) {
        ll dis;
        if (i == dayi) {
            dis = 1;
        } else {
            dis = day[i+1] - day[i];
        }
        debug(dis);
        ans += min(q[i], cost) * dis;    
    }
    cout << ans << endl;
}

// DEBUGの消去を行いましたか??