#include <bits/stdc++.h>
using namespace std;
const long long int N = 300009;
const long long int mod = 1000000007;
void pre() {}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin.exceptions(cin.failbit);
  ;
  pre();
  long long int n;
  cin >> n;
  vector<pair<pair<long long int, long long int>, long long int>> v(n);
  for (auto& it : v) {
    cin >> it.first.first >> it.second >> it.first.second;
    if (it.first.second == 1) {
      it.second = -it.second;
    } else {
      swap(it.first.first, it.second);
      it.second = -it.second;
    }
  }
  sort(v.begin(), v.end());
  multiset<long long int> s;
  long long int match = 0;
  for (auto& it : v) {
    if (it.first.second == 1) {
      s.insert(it.second);
    } else {
      if (s.upper_bound(it.second) != s.begin()) {
        auto itr = s.upper_bound(it.second);
        itr--;
        s.erase(itr);
        match++;
      }
    }
  }
  cout << n - match << "\n";
  return 0;
}
