#include <bits/stdc++.h>

#define pb(a) push_back(a)
#define rep(i, d, e) for (int i = d; i < e; i++)
#define ffor(i, a, b) for (int i = a; i <= b; i++)
#define rloop(i, c, d) for (int i = c; i >= d; i--)
#define ll long long
#define vc vector<ll>
#define pp pop_back()
#define mod 1000000007
#define MAX 1000000
using namespace std;
int main()
{
    
    ll n;
    cin >> n;
 
    double l[n], r[n];
    ffor(i, 0, n - 1)
    {
        int c;
        cin >> c >> l[i] >> r[i];
        if (c == 2)
            r[i] -= 0.5;
        if (c == 3)
            l[i] += 0.5;
        if (c == 4)
        {
            l[i] += 0.5;
            r[i] -= 0.5;
        }
    }
    ll cnt=0;
    for(int i=0;i<n-1;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(max(l[i],l[j])<=min(r[i],r[j]))
            cnt++;
        }
    }
    cout<<cnt<<endl;
}
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int i = 0; i < n; i++)

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> a(n,vector<int>(3));
    rep(i,n){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    int ans = 0;
    rep(i,n){
        for(int j = i+1; j<n; j++){
            bool ok = false;
            if(a[i][1]<=a[j][2] && a[i][2]>=a[j][1]){
                ok = true;
                if(a[i][1]==a[j][2] && !(a[i][0]<= 2&&a[j][0]%2==1))ok = false;
                else if(a[i][2]==a[j][1] && !(a[j][0]<= 2&&a[i][0]%2==1))ok = false;
            }
            if(ok)ans++;
        }
    }
    cout << ans << endl;
    return 0;
}