#include <cstdio>
#include <algorithm>
#include <memory.h>
#include <time.h>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <sstream>
#include <fstream>
#include <stack>
#include <queue>
#include <vector>
#include <iomanip>
#include <iostream>
#include <assert.h>

#define ALL(x) x.begin(), x.end()
#define fill(a) memset(a, 0, sizeof(a))
#define abs(x) ((x)>0?(x):-(x))
#define sqr(x) (1ll*(x)*(x))
#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)<(b)?(b):(a))
#define gcd(a,b) __gcd(a,b)
#define F first
#define S second
#define SS stringstream
#define CC(x) cout << x << endl
#define CCS(x) cout << x << " "
#define pw(x) (1ll<<(x))
#define pb push_back
#define mp make_pair
#define FIN freopen("1.in", "r", stdin)
#define FOUT freopen("1.out", "w", stdout)
#define FILE FIN; FOUT
#define SC(x) scanf("%d", &x)
#define PR(x) printf("%d\n", x)
#define PRS(x) printf("%d ", x)
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> > 
#define forr(i, l, r) for (int i = l; i <= r; i++)
#define SRD srand((int)time(NULL))
#define GC getchar()

typedef long long LL;
typedef unsigned long long ULL;
typedef double DD;
typedef long double LD;
typedef unsigned char UC;
typedef unsigned int UI;
typedef unsigned short US;

using namespace std;

#define N 111111

int n, sss[N], ans = 0;
pair<int, pii > a[N];
set <int> s;
set <int> :: iterator it;
vi er;

        inline int fs(int x)
        {
                int res = 0;
                for(int j = x; j >= 0; j = (j&(j+1))-1) res += sss[j];
                return res;
        }
        
        inline void upd(int x)
        {
                for(int j = x; j<=50050; j |= j+1) sss[j]++;
        }

int main(int argc, char * argv[])
{
        //ios_base::sync_with_stdio(0);
        //FIN;
        SC(n);
        forr(i, 1, n)
        {
                int x, y, z;
                SC(x); SC(y); SC(z);
                a[i] = mp(y, mp(x, z));
        }
        sort(a+1, a+n+1);
        forr(i, 0, 50001) s.insert(i);
        forr(i, 1, n)
        {
                int r = a[i].F, l = a[i].S.F, c = a[i].S.S;
                int sum = fs(r)-fs(l-1);
                if (sum >= c) continue;
                it = s.lower_bound(r);
                if (it == s.end() || *it != r) it--;
                er.clear();
                for(;;)
                {
                        if (sum == c) break;
                        sum++;
                        upd(*it);
                        ans++;
                        er.pb(*it);
                        it--;
                }
                for(int j = 0; j<er.size(); j++) s.erase(er[j]);
        }
        CC(ans);
        return 0;
}
