// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#define int long long int
#define ll long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define rep(i, init, n) for (int i = init; i < (int)n; i++)
#define rev(i, n, init) for (int i = (int)n; i >= init; i--)
#define MOD1 1e9 + 7
#define MOD2 998244353
#define f first
#define s second
#define endl '\n'
#define pii pair<int, int>
#define tii tuple<int, int>
#define all(v) v.begin(), v.end()
#define mt make_tuple
#define precise(i) cout << fixed << setprecision(i)
#define codejam cout << "Case #" << ii + 1 << ": ";
#define impossible cout << "IMPOSSIBLE" << endl;
#define error(s) throw runtime_error(s)
#define hash hash1
#define prev prev1
std::mt19937_64 gen(std::chrono::steady_clock::now().time_since_epoch().count());
std::mt19937 gen1(std::chrono::steady_clock::now().time_since_epoch().count());

//change according to int or long long int
int rng(int l, int r)
{
     return std::uniform_int_distribution<int>(l, r)(gen);
}

const long double PI = atan(1.0) * 4;
const int32_t INF32 = 2e9 + 7;
const int64_t INF64 = 3e18;
const int32_t LOG = 21;
int32_t MOD = MOD1;

using namespace std;

//-------------------DEBUGGING-------------------------
void my_debugger(string s, int LINE_NUM) { cerr << endl; }
template <typename start, typename... end>
void my_debugger(string s, int LINE_NUM, start x, end... y)
{
     if (s.back() != ',')
     {
          s += ',';
          cerr << "LINE(" << LINE_NUM << "): ";
     }
     int i = s.find(',');
     cerr << s.substr(0, i) << " = " << x;
     s = s.substr(i + 1);
     if (!s.empty())
          cerr << ", ";
     my_debugger(s, LINE_NUM, y...);
}

#ifdef AJIT
#define debug(...) my_debugger(#__VA_ARGS__, __LINE__, __VA_ARGS__);
#else
#define debug(...) ;
#endif

void setMod(int mod_val)
{
     MOD = mod_val;
}

void files_init()
{
     freopen("file.in", "r", stdin);
     freopen("file.out", "w", stdout);
}

const int N = 1e6 + 5;
const int LOGN = 20;

//-----------------------------------------------------

bool intersect(int l1,int r1,int l2,int r2,int fl1,int fr1,int fl2,int fr2)
{
     debug(l1,r1,l2,r2);
     if(l1>r2 || l2>r1 || l1>r1 || l2>r2)
     return false;

     if(l1==r2)
     {
          if(fl1 && fr2)
          return true;
          return false;
     }
     else if(l2==r1)
     {
          if(fl2 && fr1)
          return true;
          return false;
     }

     return true;
}

int32_t main()
{
     getFaster;
     //files_init();
     int tests = 1;
     //cin >> tests;
     rep(ii, 0, tests)
     {
          int n;
          cin>>n;
          vector<pii> vals(n);
          vector<pii> flag(n);
          rep(i,0,n)
          {
               int type,l,r;
               cin>>type>>l>>r;
               vals[i]={l,r};
               if(type==1)
               flag[i]={1,1};
               else if(type==2)
               flag[i]={1,0};
               else if(type==3)
               flag[i]={0,1};
               else
               flag[i]={0,0};
          }

          int ans=0;

          rep(i,0,n)
          {
               rep(j,i+1,n)
               {
                    if(intersect(vals[i].f,vals[i].s,vals[j].f,vals[j].s,flag[i].f,flag[i].s,flag[j].f,flag[j].s))
                    ans++;
               }
          }

          cout<<ans<<endl;
     }
     return 0;
}
#include <iostream>

using namespace std;

struct Interval {
  int tip;
  int left;
  int right;
};

int const NMAX = 2000;
Interval v[1 + NMAX];

bool isIntersect(Interval a, Interval b) {
  if(a.right == b.left){
    if((a.tip == 1 || a.tip == 3) && (b.tip == 1 || b.tip == 2)){// ] and [
      return true;
    }
    return false;
  }else if(a.right < b.left){
    return false;
  }
  if(b.right == a.left){
    if((b.tip == 1 || b.tip == 3) && (a.tip == 1 || a.tip == 2)){// ] and [
      return true;
    }
    return false;
  }else if(b.right < a.left){
    return false;
  }
  return true;
}

int main() {

  int n, ans = 0;
  cin >> n;
  for(int i = 1;i <= n;i++){
    cin >> v[i].tip >> v[i].left >> v[i].right;
  }
  for(int i = 1;i <= n;i++) {
    for(int j = i + 1;j <= n;j++){
      if(isIntersect(v[i], v[j])){
        ans++;
      }
    }
  }
  cout << ans;
  return 0;
}
