#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;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPG1lbW9yeS5oPgojaW5jbHVkZSA8dGltZS5oPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxjc3RkbGliPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxzc3RyZWFtPgojaW5jbHVkZSA8ZnN0cmVhbT4KI2luY2x1ZGUgPHN0YWNrPgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxpb21hbmlwPgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxhc3NlcnQuaD4KCiNkZWZpbmUgQUxMKHgpIHguYmVnaW4oKSwgeC5lbmQoKQojZGVmaW5lIGZpbGwoYSkgbWVtc2V0KGEsIDAsIHNpemVvZihhKSkKI2RlZmluZSBhYnMoeCkgKCh4KT4wPyh4KTotKHgpKQojZGVmaW5lIHNxcih4KSAoMWxsKih4KSooeCkpCiNkZWZpbmUgbWluKGEsYikgKChhKT4oYik/KGIpOihhKSkKI2RlZmluZSBtYXgoYSxiKSAoKGEpPChiKT8oYik6KGEpKQojZGVmaW5lIGdjZChhLGIpIF9fZ2NkKGEsYikKI2RlZmluZSBGIGZpcnN0CiNkZWZpbmUgUyBzZWNvbmQKI2RlZmluZSBTUyBzdHJpbmdzdHJlYW0KI2RlZmluZSBDQyh4KSBjb3V0IDw8IHggPDwgZW5kbAojZGVmaW5lIEND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bnQgZnMoaW50IHgpCiAgICAgICAgewogICAgICAgICAgICAgICAgaW50IHJlcyA9IDA7CiAgICAgICAgICAgICAgICBmb3IoaW50IGogPSB4OyBqID49IDA7IGogPSAoaiYoaisxKSktMSkgcmVzICs9IHNzc1tqXTsKICAgICAgICAgICAgICAgIHJldHVybiByZXM7CiAgICAgICAgfQogICAgICAgIAogICAgICAgIGlubGluZSB2b2lkIHVwZChpbnQgeCkKICAgICAgICB7CiAgICAgICAgICAgICAgICBmb3IoaW50IGogPSB4OyBqPD01MDA1MDsgaiB8PSBqKzEpIHNzc1tqXSsrOwogICAgICAgIH0KCmludCBtYWluKGludCBhcmdjLCBjaGFyICogYXJndltdKQp7CiAgICAgICAgLy9pb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOwogICAgICAgIC8vRklOOwogICAgICAgIFNDKG4pOwogICAgICAgIGZvcnIoaSwgMSwgbikKICAgICAgICB7CiAgICAgICAgICAgICAgICBpbnQgeCwgeSwgejsKICAgICAgICAgICAgICAgIFNDKHgpOyBTQyh5KTsgU0Moeik7CiAgICAgICAgICAgICAgICBhW2ldID0gbXAoeSwgbXAoeCwgeikpOwogICAgICAgIH0KICAgICAgICBzb3J0KGErMSwgYStuKzEpOwogICAgICAgIGZvcnIoaSwgMCwgNTAwMDEpIHMuaW5zZXJ0KGkpOwogICAgICAgIGZvcnIoaSwgMSwgbikKICAgICAgICB7CiAgICAgICAgICAgICAgICBpbnQgciA9IGFbaV0uRiwgbCA9IGFbaV0uUy5GLCBjID0gYVtpXS5TLlM7CiAgICAgICAgICAgICAgICBpbnQgc3VtID0gZnMociktZnMobC0xKTsKICAgICAgICAgICAgICAgIGlmIChzdW0gPj0gYykgY29udGludWU7CiAgICAgICAgICAgICAgICBpdCA9IHMubG93ZXJfYm91bmQocik7CiAgICAgICAgICAgICAgICBpZiAoaXQgPT0gcy5lbmQoKSB8fCAqaXQgIT0gcikgaXQtLTsKICAgICAgICAgICAgICAgIGVyLmNsZWFyKCk7CiAgICAgICAgICAgICAgICBmb3IoOzspCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzdW0gPT0gYykgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICAgIHN1bSsrOwogICAgICAgICAgICAgICAgICAgICAgICB1cGQoKml0KTsKICAgICAgICAgICAgICAgICAgICAgICAgYW5zKys7CiAgICAgICAgICAgICAgICAgICAgICAgIGVyLnBiKCppdCk7CiAgICAgICAgICAgICAgICAgICAgICAgIGl0LS07CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmb3IoaW50IGogPSAwOyBqPGVyLnNpemUoKTsgaisrKSBzLmVyYXNlKGVyW2pdKTsKICAgICAgICB9CiAgICAgICAgQ0MoYW5zKTsKICAgICAgICByZXR1cm4gMDsKfQo=