#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("inline")
#include<bits/stdc++.h>
using namespace std;
template<class T> struct cLtraits_identity{
  using type = T;
}
;
template<class T> using cLtraits_try_make_signed =
  typename conditional<
    is_integral<T>::value,
    make_signed<T>,
    cLtraits_identity<T>
    >::type;
template <class S, class T> struct cLtraits_common_type{
  using tS = typename cLtraits_try_make_signed<S>::type;
  using tT = typename cLtraits_try_make_signed<T>::type;
  using type = typename common_type<tS,tT>::type;
}
;
template<class S, class T> inline auto max_L(S a, T b)
-> typename cLtraits_common_type<S,T>::type{
  return (typename cLtraits_common_type<S,T>::type) a >= (typename cLtraits_common_type<S,T>::type) b ? a : b;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class T> int Moebius_L(T n){
  T i;
  int res = 1;
  if(n%4==0){
    return 0;
  }
  if(n%2==0){
    n /= 2;
    res = -res;
  }
  for(i=3;i*i<=n;i+=2){
    if(n%i==0){
      n /= i;
      res = -res;
    }
    if(n%i==0){
      return 0;
    }
  }
  if(n > 1){
    res = -res;
  }
  return res;
}
long long L;
long long R;
long long res;
long long solve(){
  long long i;
  long long res = 0;
  res += R - L;
  for(i=(2);i<(R+1);i++){
    res -=Moebius_L(i)* (R/i - L/i) * (R/i - L/i);
  }
  for(i=(max_L(2, L+1));i<(R+1);i++){
    res -= (R / i) * 2;
  }
  if(L == 0){
    res--;
  }
  return res;
}
int main(){
  rd(L);L += (-1);
  rd(R);
  res = solve();
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay version 20210619-1 [beta]

// --- original code ---
// ll L, R, res;
// 
// ll solve(){
//   ll i, res = 0;
//   res += R - L;
//   rep(i,2,R+1) res -= Moebius(i) * (R/i - L/i) * (R/i - L/i);
//   rep(i,max(2,L+1),R+1) res -= (R / i) * 2;
//   if(L == 0) res--;
//   return res;
// }
// 
// {
//   rd(L--,R);
//   res = solve();
//   wt(res);
// }

#include <bits/stdc++.h>
using namespace std;
struct binary_indexed_tree{
  int N;
  vector<int> BIT;
  binary_indexed_tree(int N): N(N), BIT(N + 1, 0){
  }
  void add(int i, int x){
    i++;
    while (i <= N){
      BIT[i] += x;
      i += i & -i;
    }
  }
  int sum(int i){
    int ans = 0;
    while (i > 0){
      ans += BIT[i];
      i -= i & -i;
    }
    return ans;
  }
  int sum(int L, int R){
    return sum(R) - sum(L);
  }
};
int main(){
  int N;
  cin >> N;
  vector<int> l(N), r(N);
  for (int i = 0; i < N; i++){
    int t;
    cin >> t >> l[i] >> r[i];
    l[i] *= 2;
    r[i] *= 2;
    if (t == 3 || t == 4){
      l[i]++;
    }
    if (t == 1 || t == 3){
      r[i]++;
    }
  }
  vector<int> x;
  for (int i = 0; i < N; i++){
    x.push_back(l[i]);
    x.push_back(r[i]);
  }
  sort(x.begin(), x.end());
  x.erase(unique(x.begin(), x.end()), x.end());
  int M = x.size();
  for (int i = 0; i < N; i++){
    l[i] = lower_bound(x.begin(), x.end(), l[i]) - x.begin();
    r[i] = lower_bound(x.begin(), x.end(), r[i]) - x.begin();
  }
  binary_indexed_tree L(M), R(M);
  long long ans = 0;
  for (int i = 0; i < N; i++){
    ans += i;
    ans -= R.sum(l[i] + 1);
    ans -= L.sum(r[i], M);
    L.add(l[i], 1);
    R.add(r[i], 1);
  }
  cout << ans << endl;
}