#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,k,n)      for(int i=k;i<n;i++)
#define all(x)          x.begin(),x.end()
#define sz(x)           (int) x.size()
#define pii             pair<int,int>
#define debug(x)        cerr << #x << " : " << x << "\n";
#define int             ll
/*############################ !!SOLVE!! ################################*/

struct interval{
    int t;
    int x;
    int y;
};

void solve(){

  int n;
  cin >> n;

  vector <interval> seg(n);
  
  rep(i,0,n){
      cin >> seg[i].t >> seg[i].x >> seg[i].y;
  }
  int intersections = 0;
  for(int i = 0 ;i < n ; i++){
      interval one = seg[i];
      for(int j = i+1;j<n;j++){
          interval two = seg[j];

          if(one.x < two.x){
              if(two.x < one.y){
                  intersections++;
              }

              if(one.y == two.x){
                  if((one.t == 1 || one.t == 3) and (two.t == 1 || two.t == 2))
                    intersections++;
              }

              
          }

          else{
              if(one.x < two.y){
                  intersections++;
              }

              if(one.x == two.y){
                  if((two.t == 1 || two.t == 3) and (one.t == 2 || one.t == 1))
                    intersections++;
              }
          }
      }
   
  }

  cout << intersections << "\n";



}

/*######################## !!TESTCASES!! ################################*/
signed main(){
    ios ::sync_with_stdio(0);
    cin.tie(0);
    int testcases = 1;

    while(testcases -->0){
        solve();
    }
}

        
#include <bits/stdc++.h>
#include <set>
#define ll long long
#include <string>
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323846
#define mod 1000000007
#define INF 1e18
// typedef pair<ll, ll> pi;
#define rep(i,n) for(i=0;i<n;i++)
#define repk(i,k,n) for(i=k;i<n;i++)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define oset tree <pair<ll int ,ll int>, null_type, less<pair<ll int,ll int> >, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define see(args...)                             \
        {                                            \
            cerr << "LINE " << __LINE__;             \
            string _s = #args;                       \
            replace(_s.begin(), _s.end(), ',', ' '); \
            stringstream _ss(_s);                    \
            istream_iterator<string> _it(_ss);       \
            err(_it, args);                          \
            cerr << endl;                            \
        }
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << ' ' << *it << " = " << a;
    err(++it, args...);
}
void fastio()
{
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

}
void solve()
{
    string s; cin >> s;
    string s2 = "ZONe";
    ll int i, ans = 0;
    rep(i, 12)
    {
        if (i + 3 < 12)
        {
            if (s.substr(i, 4) == s2)ans++;
        }
    }
    cout << ans << endl;

}
int main()
{
    fastio();
    ll int t;
    // cin >> t;
    t = 1;
    while (t--)
    {
        solve();
    }

}