#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool testOverlap(ll x1, ll x2, ll y1, ll y2) {
  return (x1 >= y1 && x1 <= y2) ||
         (x2 >= y1 && x2 <= y2) ||
         (y1 >= x1 && y1 <= x2) ||
         (y2 >= x1 && y2 <= x2);
}
bool is_overlapping(double x1,double x2,double y1,double y2){
    return max(x1,y1) <= min(x2,y2);}
int main(){
	
int t;
t=1;
while(t--){
   ll n;
   cin>>n;
   vector<pair<double,double>>v;
   ll a[n];
   ll count=0;
   ll tc;
   double a1,b1;
   for(ll i=0;i<n;i++){
      cin>>tc>>a1>>b1;
      a[i]=tc;
      v.push_back({a1,b1});
         }
for(ll i=0;i<n-1;i++){
   for(ll j=i+1;j<n;j++){
    //  if(i!=j){
         ll k1=a[i];
         ll k2=a[j];
         double x1=v[i].first;
         double x2=v[i].second;
         if(k1==2){
            x2-=0.5;
         }
         else if(k1==3){
            x1+=0.5;
         }
         else if(k1==4){
            x1+=0.5,x2-=0.5;
         }
         double y1=v[j].first;
         double y2=v[j].second;
         if(k2==2){
            y2-=0.5;
         }
         else if(k2==3){
            y1+=0.5;
         }
         else if(k2==4){
            y1+=0.5,y2-=0.5;
         }
         if(is_overlapping(x1,x2,y1,y2))
            count++;



    //  }
   }
}
cout<<count;



} 


	

}

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

#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#define debug(x)			\
    for(auto element:x)     \
        cout<<element<<" "; \
    cout<<endl
#define debugp(x)          \
for (auto element : x)     \
    cout << element.first << " " << element.second << endl
#define db(x) cout << #x << " = " << x << '\n'
#define makegraph(adj, num)   \
for (int i = 0; i < num; i++) \
{                             \
    int u, v;                 \
    cin >> u >> v;            \
    adj[u].push_back(v);      \
    adj[v].push_back(u);      \
}
#define rep(i,k,n) for(int i=k;i<n;i++)
#define rept(i,k,n) for(auto i=k;i!=n;++i)
#define drep(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define endl '\n'
#define ld long double
#define int long long
#define clr(s) memset(s,0,sizeof(s))
#define valset(arr,size,val) rep(i,0,size) arr[i]=val;
#define Tj return
#define out 0
#ifdef segtree
    #define left st,(st+en)/2,2*ind+1,seg
    #define right (st+en)/2+1,en,2*ind+2,seg
    #define lidx 2*ind+1
    #define ridx 2*ind+2
    #define mid (st+en)/2
#endif // segtree
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> ii;
typedef pair<int,pair<int,int>> iii;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef map<char,int> mci;
typedef set<int> si;
const int intmax = 2147483647;
const int intmin = -2147483648;
const int mod = 1000000007;
const int mod2 = 998244353;

template<typename... T>
void read(T&... args)
{
    ((cin >> args ), ...);
}

template<typename... T>
void print(T... args)
{
    ((cout << args << " "), ...);
    cout<<endl;
}


void solve()
{
    int n;
    cin >> n;
    vector<iii> v(n);
    rep(i,0,n) cin>>v[i].first>>v[i].second.first>>v[i].second.second;
    int ans = 0,c=0;
    rep(i,0,n){
        rep(j,i+1,n){
            if((v[i].second.first >= v[j].second.first and v[i].second.first <= v[j].second.second) or (v[i].second.second >= v[j].second.first and v[i].second.second <= v[j].second.second) or (v[j].second.first >= v[i].second.first and v[j].second.second <= v[i].second.second)) {
                //c++;
                ans++;//print(i,j);
                if((v[i].second.second == v[j].second.first and (v[i].first==2 or v[i].first == 4 or v[j].first == 3 or v[j].first == 4)) or (v[j].second.second == v[i].second.first and (v[j].first==2 or v[j].first == 4 or v[i].first == 3 or v[i].first == 4))) ans--;
            }
        }
    }
    //db(c);
    print(ans);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    while(t--)
        solve();
    Tj out;
}