#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1e9
typedef long long ll;
typedef long double ld;

int main(){
  ll n;
  cin >> n;
  vector<pair<double,double>> v(n);
  REP(i,n){
    ll t;
    double l, r;
    cin >> t >> l >> r;
    if(t == 2)r-=0.1;
    else if(t==3)l+=0.1;
    else if(t==4){
      l+=0.1;
      r-=0.1;
    }
    v[i] = {l,r};
  }
  ll cnt = 0;
  REP(i,n-1){
    FOR(j,i+1,n){
      if(v[j].first <= v[i].second && v[i].first <= v[j].second)cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll inf = (1ll << 60);
vector<int> dy {0,1,0,-1};
vector<int> dx {-1,0,1,0};// ← ↓ → ↑

int main(){
    ll x, y; cin >> x >> y;
    ll a, b; cin >> a >> b;
    ll ans = 0;
    while(1){
        if(x > y/a) break;
        if(a*x >= y) break;
        if(a*x >= x + b) break;
        x *= a;
        ans++;
    }
    ans += (y-x-1)/b;
    cout << ans << endl;
}
