#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int N;
    cin >> N;
    double t[N], l[N], r[N], between[N];
    int ans =0;
    
    for (int i=0;i<N;i++) {
        cin >> t[i] >> l[i] >> r[i];
        
        if (t[i] == 1) {
            
        }
        else if (t[i] == 2) {
            r[i]-=0.2;
        }
        else if (t[i] == 3) {
            l[i]+=0.2;
        }
        else if (t[i] == 4) {
            l[i]+=0.2;
            r[i]-=0.2;
        }
        between[i] = r[i] - l[i];
    }
    for (int i=0;i<N;i++) {
        for (int j=i+1;j<N;j++) {
            if ((r[i] < l[j]) || (r[j] < l[i])) {
                
            }
            else {
                ans += 1;
            }
        }
    }
    
    
    cout << ans <<endl;
    
    return 0;
}

#include <map>
#include <cmath>
#include <ctime>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define Lc(x) x << 1
#define Rc(x) x << 1 | 1
#define Int register int
#define Lowbit(x) ((x) & -(x))
#define Swap(a, b) a ^= b ^= a ^= b
#define Abs(x) ((x) < 0 ? -(x) : (x))
#define Max(x, y) ((x) < (y) ? (y) : (x))
#define Min(x, y) ((x) < (y) ? (x) : (y))
#define Isdigit(ch) (ch >= '0' and ch <= '9')

const double Pi = acos (-1.0);
const int MAXN = 1e4 + 10, MAXM = 2e2 + 10;
const LL Mod = 1e9 + 7, INF = 1LL << 60, Inv2 = 5e8 + 4;

inline LL Read () {
	LL f = 0, x = 0;
	char ch = getchar ();
	
	while (!isdigit (ch) ) {
		f |= (ch == '-'), ch = getchar ();
	}
	
	while (isdigit (ch) ) {
		x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar ();
	}
	
	return f ? -x : x;
}

inline void Write (const LL x) {
	if (x < 0 ) {
		putchar ('-'), Write (-x);
		return ;
	}
	
	if (x > 9 ) {
		Write (x / 10);
	}
	
	putchar ((x % 10) ^ 48);
	return ;
}

LL Answer;
int BIT[MAXN], Temp[MAXN], Left[MAXN], Right[MAXN];
int n, m, Opt;

inline void Modify (int Index, int Val) {
	while (Index <= m ) {
		BIT[Index] += Val, Index += Lowbit (Index);
	}
	
	return ;
}

inline LL Query (int Index) {
	LL Res = 0;
	
	while (Index ) {
		Res += BIT[Index], Index -= Lowbit (Index);
	}
	
	return Res;
}

signed main () {
	n = Read ();
	Int i, j;
	
	for (i = 1; i <= n; ++ i ) {
		Opt = Read (), Left[i] = Read () * 2, Right[i] = Read () * 2;
		
		if (Opt % 2 == 0 ) {
			-- Right[i];
		}
		
		if (Opt > 2 ) {
			++ Left[i];
		}
	}
	
	for (i = 1; i <= n; ++ i ) {
		for (j = i + 1; j <= n; ++ j ) {
			if ((Left[i] <= Left[j] and Right[i] >= Left[j]) or (Left[i] <= Right[j] and Right[i] >= Right[j]) or (Left[i] >= Left[j] and Right[i] <= Right[j]) ) {
				++ Answer;
			}
		}
	}
	
	printf ("%lld\n", Answer);
	return 0;
}
