#include <bits/stdc++.h>
//#include <bits/extc++.h>
//#include <immintrin.h>

using namespace std;

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


template<typename T>
istream &operator>>(istream &in, vector<T> &a) {
    for (auto &i : a)
        in >> i;
    return in;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &a) {
    for (auto &i : a) {
        out << i << " ";
    }
    return out;
}

template<typename T, typename D>
istream &operator>>(istream &in, pair<T, D> &a) {
    in >> a.first >> a.second;
    return in;
}

template<typename T, typename D>
ostream &operator<<(ostream &out, const pair<T, D> &a) {
    out << a.first << " " << a.second;
    return out;
}

struct LogOutput {
    template<typename T>
    LogOutput &operator<<(const T &x) {
#ifdef DIVAN
        cout << x;
#endif
        return *this;
    }
} dout, fout;

typedef long long ll;
typedef unsigned long long ull;
typedef double dl;
typedef complex<double> cd;

#define nl '\n'
#define elif else if
#define all(_v) _v.begin(), _v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define sqr(_v) ((_v) * (_v))
#define eb emplace_back
#define pb push_back
#define mod(x, m) ((x) >= 0 ? ((x) % m) : ((((x) % m) + m) % m))
#define minq(x, y) x = min((x), (y))
#define maxq(x, y) x = max(x, (y))
#define forn(i, n) for (int i = 0; i < (n); ++i)

typedef vector<pair<int,int>> vpi;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;


const ll INFL = 9187201950435737471;
const ll nINFL = -9187201950435737472;
const int INF = 2139062143;
const int nINF = -2139062144;
const ull ULINF = numeric_limits<ull>::max();
const long double PI = acos(-1);
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rnd(seed);

inline void IO() {
#ifdef DIVAN
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
#else
    //    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
}

struct Point{
    int coord;
    bool include;
    bool open;
    int num;
    Point(int a = 0, bool b = 0, bool c = 0, int x = 0) {
        coord = a;
        include = b;
        open = c;
        num = x;
    }
    bool operator<(const Point& x) const {
        if (coord != x.coord) {
            return coord < x.coord;
        }
        if (include ^ x.include) {
            return include;
        }
        if (x.open == open) {
            return 0;
        }
        return open;
    }
};

void Solve() {
    int n;
    cin >> n;
    vpi a(n);
    forn(i, n) {
        int t, l, r;
        cin >> t >> l >> r;
        l *= 2;
        r *= 2;
        if (t > 2) {
            ++l;
        }
        if (t == 2 || t == 4) {
            --r;
        }
        a[i] = {l, r};
    }
    int ans = 0;
    forn(i, n) {
        for (int j = i + 1; j < n; ++j) {
            if (a[i].first > a[j].second || a[j].first > a[i].second) {
                continue;
            }
            ++ans;
        }
    }
    cout << ans;
}

signed main() {
    auto startTime = chrono::high_resolution_clock::now();
    IO();
    int t = 1;
//    cin >> t;
    for (int i = 1; i <= t; ++i) {
//        cout << "Case #" << i << ": ";
        Solve();
    }
    auto endTime = chrono::high_resolution_clock::now();
    chrono::duration<long double> duration = endTime - startTime;
    cout << setprecision(6) << fixed;
    fout << '\n' << "Time: " << duration.count();
    return 0;
}

using namespace std;
#include<bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define double long double

const int N = 2e3+3;
pair<int,int>a[N];

bool intersect(int i, int j)
{
    vector< pair<int,int> >v;
    v.push_back( a[i] );
    v.push_back( a[j] );
    sort( all(v) );
    return ( v[0].second >= v[1].first );
}

signed main()
{
    IOS;
    int n; cin >> n;
    for ( int i = 1; i <= n; ++i )
    {
        int t; cin >> t;
        cin >> a[i].first >> a[i].second;
        a[i].first *= 1e9;
        a[i].second *= 1e9;

        if ( t == 2 )
            a[i].second -= 1;
        
        if ( t == 3 )
            a[i].first += 1;

        if ( t == 4 )
        {
            a[i].first += 1;
            a[i].second -= 1;
        }
    }

    int ans = 0;

    for ( int i = 1; i <= n; ++i )
    {
        for ( int j = i + 1; j <= n; ++j )
            ans += intersect(i, j);
    }

    cout << ans << '\n';
}
