#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define Rep(i,n) for(int i=0;i<=(int)n;i++)
const ll mod = 1e9+7 ;
const ll INF = 1e18 ;
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}


int main(){
    ll n;
    cin >> n;
    vector<double> le(n);
    vector<double> ri(n);
    rep(i,n) {
        int t;
        double l, r;
        cin >> t >> l >> r;
        if(t == 2) r -= 0.01; 
        if(t == 3) l += 0.01;
        if(t == 4) {
            l += 0.01;r -= 0.01;
        }
        le.at(i) = l;
        ri.at(i) = r;
    }
    ll ans = 0;
    rep(i,n) {
        for(int j = i + 1; j < n; j++) {
            if(le.at(i) <= le.at(j)) {
                if(ri.at(i) < le.at(j)) continue;
                else ans++;
            }
            else {
                if(ri.at(j) < le.at(i)) continue;
                else ans++;
            }
        }
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;

int main() {
    long long N, count = 0;
    cin >> N;
    vector<vector<long long>> A(N, vector<long long>(3));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> A.at(i).at(j);
        }
    }
    for (int i = 0; i < (N - 1); i++) {
        for (int j = i; j < (N - 1); j++) {
            if (A.at(i).at(2) > A.at(j + 1).at(1)) {
                if (A.at(i).at(1) < A.at(j + 1).at(2)) {
                    count++;
                }
                else if (A.at(i).at(1) == A.at(j + 1).at(2)) {
                    if (A.at(i).at(0) == 1 || A.at(i).at(0) == 2) {
                        if (A.at(j + 1).at(0) == 1 || A.at(j + 1).at(0) == 3) {
                            count++;
                        }
                    }
                }
            }
            else if (A.at(i).at(2) == A.at(j + 1).at(1)) {
                if (A.at(i).at(0) == 1 || A.at(i).at(0) == 3) {
                    if (A.at(j + 1).at(0) == 1 || A.at(j + 1).at(0) == 2) {
                        count++;
                    }
                }
            }
        }
    }
    cout << count << endl;
}