/*  **    ** ******    ****** ****** **     ******    ***
    **    ** **  **    **  ** **  ** **     **  ** *********
    **\../** ******    ****** **  ** ****** **  **    ***
    **    ** ** **     ** **  **  ** **  ** **  **    *****
    **    ** **  ** ** **  ** ****** ****** ******    *****
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define PI  3.14159265358979323846
#define lp(i,n) for(int i = 0; i <n;i++)
#define rlp(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define fr first
#define sc second
#define vt vector 
#define sz(v) ((int)((v).size()))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
template<class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;
int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0};
void init(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
template<class T> void read(T& x) {
	cin >> x;
}
void read(double& d) {
	string t;
	read(t);
	d=stod(t);
}
void read(long double& d) {
	string t;
	read(t);
	d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
	read(h);
	read(t...);
}
template<class A> void read(vt<A>& x) {
	for(auto& a:x)
		read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
	for(auto& a:x)
		read(a);
}	
void _run(){
	int a,b,c,d;
	read(a,b,c,d);
	int cnt =0;
	while(a--&&b--&&c--&&d--)cnt++;
	cout<<cnt<<endl;
}
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
	init();
    int t=1;
    // read(t);
    while(t--)_run();
    
    return 0;
}
#include <bits/stdc++.h>
#define N 200005
#define int long long
using namespace std;

void solve(){
    int n;
    cin >> n;
    vector<pair<int,int>> v;
    for(int i=0;i<n;i++){
        int t,l,r;
        cin >> t >> l >> r;
        l *=2;
        r *=2;
        if(t  == 2 || t == 4)r--;
        if(t  == 3 || t == 4)l++;
        if(l <= r)
        v.push_back({l,r});
    }
    int ans = 0;
    for(int i=0;i<v.size();i++){
        for(int j=0;j<i;j++){
            auto u = v[i];
            auto k = v[j];
            if(!(k.second < u.first || u.second < k.first)){
                ans++;
            }
        }
    }
    cout << ans;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef Local
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    #ifdef Local
    cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}