#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll is_valid(double x1, double y1, double x2, double y2)   {
    if(y1 >= x2 && x1 <= x2)    {
        return 1;
    }
    if(x1 <= y2 && x2 <= x1)    {
        return 2;
    }
    if(x1 <= x2 && y1 >= y2)    {
        return 3;
    }
    if(x2 <= x1  && y2 >= y1)   {
        return 4;
    }
    return -1;
}
int main()  
{
    ll n;
    cin >> n;
    double arr[3][n];
    for(int i = 0; i < n; i++)  {
        for(int  j = 0; j < 3; j++) {
            cin >> arr[j][i];
        }
        if(arr[0][i] == 2)  {
            arr[2][i] -= 0.1;
        }
        if(arr[0][i] == 3)  {
            arr[1][i] += 0.1;
        }
        if(arr[0][i] == 4)  {
            arr[1][i] += 0.1;
            arr[2][i] -= 0.1;
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++)  {
        for(int j = i+1; j < n; j++)    {
            ll val = is_valid(arr[1][i], arr[2][i], arr[1][j], arr[2][j]);
            ll now = 0;
            if(val != -1)    {
                if(val == 1)    {
                    now = arr[2][i] - arr[1][j] + 1;
                    ans++;
                }
                else  if(val == 2)  {
                    now = arr[2][j] - arr[1][i] + 1;
                    ans++;
                }
                else if(val == 3)   {
                    now = arr[2][j] - arr[1][j] + 1;
                    ans++;
                }
                else    {
                    now = arr[2][i] - arr[1][i] + 1;
                    ans++;
                }
            }
            //cout << i << " " << j << " " << val << "\n";
            
        }
    }
    cout << ans << "\n";
}
    
    


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long
#define ld long double
#define ull unsigned long long
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// #define endl "\n"
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output 

int main() {
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    ll n;
    cin>>n;
    ll t[n];
    ll l[n];
    ll r[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>t[i]>>l[i]>>r[i];
    }

    ll ans=0;

    for (int i = 0; i < n; ++i)
    {
        ll si=l[i];
        ll ei=r[i];

        for (int j = i+1; j < n; ++j)
        {
            ll sj=l[j];
            ll ej=r[j];

            if(si>ej || sj>ei){
                continue;
            }
            else{
                if(si==ej){
                    if((t[j]!=2) && (t[i]!=3) && (t[i]!=4) && (t[j]!=4)){
                        ans++;
                    }
                }
                else if(sj==ei){
                    if((t[j]!=3) && (t[i]!=2) && (t[i]!=4) && (t[j]!=4)){
                        ans++;
                    }
                }
                else{
                    ans++;
                }
            }
        }
    }
    cout<<ans;

    return 0;
}