#include <bits/stdc++.h>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#define loop(i,a,b) for (int i = (a); i <= (b); i++)
#define loopr(i, a, b) for(int i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define mp(a,b) make_pair(a,b)
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long int
#define mod 1000000007
#define mod1 998244353
using namespace std;

bool decToOctal(int n)
{
     
    // array to store octal number
    int octalNum[100];
 
    // counter for octal number array
    int i = 0;
    while (n != 0) {
 
        // storing remainder in octal array
        octalNum[i] = n % 8;
        n = n / 8;
        i++;
    }
 
 	int ok = 0;
    // printing octal number array in reverse order
    for (int j = i - 1; j >= 0; j--)
    {
		if(octalNum[j]==7)
		{
			ok = 1;
			break;
		}
	}
	if(ok)
	{
		return false;
	}
	else
	{
		return true;
	}
}

int main()
{	
	int n;
	cin>>n;
	int ans = 0;
	loop(i,1,n)
	{
	int x = 0;
	string s = to_string(i);
	x = count(s.begin(),s.end(),'7');
	if(x==0 and decToOctal(i)==true)
	{
		ans++;
	}
	}
	cout<<ans;
}
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define FOR(i, a) for(int i = 0; i < (a); ++i)
#define rrep(i, a, b) for(int i = a; i >= (b); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)(x).size()
#define ft first
#define sd second
#define pb push_back
#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;

const ll MOD = 1000000007;


void solve(){
    int n;cin>>n;
    int t[n];
    double r[n],l[n];
    rep(i,0,n) {
        cin>>t[i]>>l[i]>>r[i];
        if (t[i]==2) r[i]-=0.01;
        else if (t[i]==3) l[i]+=0.01;
        else if (t[i]==4) {
            l[i]+=0.01;
            r[i]-=0.01;
        }
    }
    int ans(0);
    rep(i,0,n){
        rep(j,i+1,n){
            if (l[i]>r[j] || r[i]<l[j]){
                //cout<<l[i]<<" "<<r[i]<<" "<<l[j]<<" "<<r[j]<<endl;
                continue;
            }
            else {
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t(1);//cin>>t;
    while (t--){
        solve();
    }
	return 0;
}

