//#include <atcoder/maxflow.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>


#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <iterator>
#include <random>
#include <chrono>
#include <complex>
#include <bitset>
#include <fstream>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
//using namespace __gnu_pbds;
//using namespace atcoder;
using namespace std;
 
const ll modd = (1000LL * 1000LL * 1000LL + 7LL);
//const ll modd = 998244353;


int main(int argc, char *argv[])   {


    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no

    ios_base::sync_with_stdio(false);
    cin.tie(0);
 
    cout.precision(12);

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readstring(s);
        bool reverse = false;
        deque<char> out;
        for(char c : s) {
            if (c=='R') {
                reverse = !reverse;
            } else {
                if (reverse) {
                    out.push_front(c);
                    if ((out.size()>=2) && (out[0]==out[1])) {
                        out.pop_front(); out.pop_front();
                    }
                } else {
                    out.push_back(c);
                    if ((out.size()>=2) && (out.back()==*prev(out.end(), 2))) {
                        out.pop_back(); out.pop_back();
                    }
                }
            }
        }

        forr(i,0,out.size()) {
            if (reverse) {
                cout << out[out.size()-1-i];
            } else {
                cout << out[i];
            }
        }
        cout << endl;
    }

 
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, n) for (int i = (int)(l); i < (int)(n); i++)
#define drep(i, n, l) for (int i = (int)(n); i > (int)(l); i--)
#define INF INT_MAX
#define INFF (pow(2,64))
#define def (200007)
#define MOD (1000000007)
typedef int64_t intt;
typedef vector<int> veci;
typedef vector<vector<int>> Veci;
typedef vector<int64_t> vecit;
typedef vector<vector<int64_t>> Vecit;
typedef vector<vector<double>> Vecd;
typedef vector<double> vecd;
typedef pair<intt, intt> P;
typedef unordered_set<int> uset;
typedef unordered_set<intt> usett;


int main(){
  int N;cin>>N;
  Vecit g(N,vecit(3));
  int ans=0;
  rep(i,0,N){
    intt t,l,r;cin>>t>>l>>r;
    g[i]={l,r,t};
  }
  sort(g.begin(),g.end());

  rep(i,0,N){
    rep(j,i+1,N){
      if(g[i][2]==1 || g[i][2]==3){
        if(g[j][2]==1 || g[j][2]==2){
          if(g[i][1]<g[j][0]){
            continue;
          }
        }else{
          if(g[i][1]<=g[j][0]){
            continue;
          }
        }
      }else{
        if(g[i][1]<=g[j][0])continue;
      }
      ans++;
    }
  }
  cout<<ans<<endl;
}