#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

typedef   vector<ll>  vi;
typedef   vector<pair<ll, ll> > vii;
typedef   pair<ll,ll> pii; 
typedef   multiset<pair<ll, ll> > msii;
typedef   multiset<ll> msi;
typedef   set<pair<ll, ll> > sii;
typedef   set<ll> si;
typedef   map<ll, ll> mii;

#define boost 	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define for1(x, a, b)  for(x=a; x<b; x++)
#define for2(x, a, b)  for(x=a, x>=b; x--)
//#define endl 	"\n"
#define all(x)  x.begin(), x.end()
#define p       pair
#define mp      make_pair
#define read    freopen("input.txt","r",stdin)
#define write   freopen("output.txt","w",stdout)
#define pb      push_back
#define ff      first
#define ss      second
#define bb      begin
#define arr_ub(arr, n, x) upper_bound(arr, arr+n, x)-arr
#define arr_lb(arr, n, x) lower_bound(arr, arr+n, x)-arr
#define u_p(v, x) upper_bound(v.begin(), v.end(), x)-v.begin()
#define l_b(v, x) lower_bound(v.begin(), v.end(), x)-v.begin()

const ll sz=1e6+123;
#define INF 1000000000000000007
#define MOD 1000000007
#define stringLen 18446744073709551620
#define pi 3.1415926536

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll n;

int main(){
    
    cin >> n;
    vector<vector<ll>> T(n, vector<ll>(3)); //l, r, t
    for(int i=0; i<n; ++i){
        vector<ll> tmp(3);
        cin >> tmp[2] >> tmp[0] >> tmp[1];
        T[i] = tmp;
    }
    
    sort(all(T), [](const vector<ll>& a, const vector<ll>& b){
        return a[0] < b[0];
    });

    ll ans = 0;
    for(int i=0; i<n-1; ++i){
        int j= i+1;
        while(( T[i][1] >= T[j][0]  || T[i][0] == T[j][0] )&& j<n){
            // if (T[i][0] == T[j][0]){
            //     if(T[i][2]==3 || T[i][2]==4 || T[j][2] == 3 || T[j][2] == 4) {
            //         j++;
            //         continue;
            //     }
            // }
            if (T[i][1] == T[j][0]){
                if(T[i][2]==2 || T[i][2]==4 || T[j][2] == 3 || T[j][2] == 4) {
                    j++;
                    if(j >= n){
                        break;
                    }
                    continue;
                }
            }
            ans++;
            j++;
            if(j>=n){
                break;
            }
        }
    }
    cout << ans;

    return 0;
}
#include "bits/stdc++.h"
using namespace std;

int main()
{
    int N; cin >> N;
    double l[N], r[N];

    for (int i = 0; i < N; i++)
    {
        int t; cin >> t >> l[i] >> r[i];
        t--;
        if (t & 1) r[i] -= 0.5;
        if (t & 2) l[i] += 0.5;
    }
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            ans += (max(l[i], l[j]) <= min(r[i], r[j]));
        }
    }

    cout << ans << '\n';
    return 0;
}