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

#define int int long long
#define fr(i, n) for (int i = 0; i < n; i++)
#define fr1(i, n) for (int i = 1; i <= n; i++)
#define S second
#define F first
#define pb(n) push_back(n)
#define endl "\n"
int mod = 1e9 + 7;
vector<int> v[1000001], tr[100001];
int level[1000001] = {0};
int in[1000001] = {0};
int out[1000001] = {0};
int low[1000001] = {0};
int vis[1000001] = {0};
int visit[1001][1001] = {0};
int dis[1001][1001] = {0};
int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
int timer, n, m, t, k, q, eq = 0;

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  t = 1;
  //
  while (t--)
  {
    cin >> n;
    double te = 0.01;
    pair<double, double> a[n];
    fr(i, n)
    {
      double x, l, r;
      cin >> x >> l >> r;
      if (x == 2)
      {
        r -= te;
      }
      if (x == 3)
      {
        l += te;
      }
      if (x == 4)
      {
        l += te, r -= te;
      }
      a[i] = {l, r};
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
      for (int j = i - 1; j >= 0; j--)
      {
        if (a[i].F > a[j].S || a[i].S < a[j].F)
        {
          continue;
        }
        else
        {
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
}

#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define lli long long int
#define pi pair<lli,lli>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i,a,b) for(lli i=a;i<b;i++)
#define all(x) x.begin(), x.end()
const lli inf=10000000000000000;
lli mod = 1e9+7;
//const long double pi = 3.14159265358979323846264338;
lli powmod(lli x,  lli y, lli p){lli res=1;x=x%p;if(x==0)return 0;while(y>0){if(y&1)res=(res*x)%p;y = y>>1;x=(x*x)%p;}return res;}
lli _pow(lli a, lli b){if(!b)return 1;lli temp = _pow(a, b / 2);temp = (temp * temp);if(b % 2)return (a * temp);return temp;}
bool isPrime(lli n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(lli i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
lli lcm(lli a, lli b){ return a * b / __gcd(a, b);}
lli  cl(lli  a,lli  x){if(a%x==0)return a/x;else return a/x+1;}




int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;  
    //cin >> t;
while(t--) {
    lli n,b,c;
    cin >> n;
    vector <lli> v(n);
    vector <pi> a(n);
    for(lli i=0;i<n;i++){
        cin >> v[i] >> b >> c;
        a[i] = (mp(b, c));
    }  
    lli cn=0;
    for(lli i=0;i<n;i++){
        for(lli j=i+1;j<n;j++){
            lli q = a[i].fi,w = a[i].se,e = a[j].fi,r = a[j].se;
            if(max(q,e)<min(w,r)){
                cn++;
            }
            else if(max(q,e)==min(w,r)){
                if(q>e&&(v[i]==1||v[i]==2)&&(v[j]==1||v[j]==3))cn++;
                if(q<e&&(v[i]==1||v[i]==3)&&(v[j]==1||v[j]==2))cn++;

            }

        }
    }
    cout<<cn<<endl;
}
}

