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

int main() {
  ll N;
  cin >> N;
  vector<pair<pair<ll, ll>, int>> lrt(N);
  for (int i = 0; i < N; i++){
    ll a, b, c;
    cin >> a >> b >> c;
    lrt.at(i).first.first = b;
    lrt.at(i).first.second = c;
    lrt.at(i).second = a;
  }
  sort(lrt.begin(), lrt.end());
  ll count = 0;
  for (int i = 0; i < N; i++) {
    if (lrt.at(i).second == 1 || lrt.at(i).second == 3) {
      for (int j = i + 1; j < N; j++) {
        if (lrt.at(i).first.second > lrt.at(j).first.first) {
          count++;
        }
        else if (lrt.at(i).first.second == lrt.at(j).first.first && lrt.at(j).second == 1) {
          count++;
        }
        else if (lrt.at(i).first.second == lrt.at(j).first.first && lrt.at(j).second == 2) {
          count++;
        }
      }
    }
    if (lrt.at(i).second == 2 || lrt.at(i).second == 4) {
      for (int j = i + 1; j < N; j++) {
        if (lrt.at(i).first.second > lrt.at(j).first.first) {
          count++;
      }
    }
  }
}
  cout << count << endl;
}

#include<iostream>
#include<cstdlib>
#include<utility>
#include<tuple>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<queue>
#include<deque>
#include<bitset>
#include<cmath>
#include<map>
#include<string>
#include<list>
#include<iomanip>
#include<set>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const double PI = acos(-1);
#define rep(i, a, b) for(ll i = a; i < b; i++)
ll MOD(ll x) {
	return (x % mod + mod) % mod;
}

int main() {

	ll n; cin >> n;
	ll mini = mod, maxi = -1;
	vector<double>t(n), l(n), r(n);
	ll ans = 0;
	rep(i, 0, n) {
		cin >> t[i] >> l[i] >> r[i];
		if (t[i] == 2)r[i] -= 0.5;
		else if (t[i] == 3)l[i] += 0.5;
		else if (t[i] == 4) {
			r[i] -= 0.5; l[i] += 0.5;
		}
		rep(j, 0, i) {
			if (l[i] >= l[j] && l[i] <= r[j])ans++;
			else if (r[i] <= r[j] && r[i] >= l[j])ans++;
			else if (l[i] <= l[j] && r[i] >= r[j])ans++;
		}
	}
	cout << ans << endl;

	return 0;
}