#include <bits/stdc++.h>
#define REP(i, n)   for(int i=0; i<(int)(n); ++i)
#define ALL(x)      (x).begin(), (x).end()
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b; return true;} return false;}

using namespace std;

int main(){
  int n; cin >> n;
  vector<int> t(n);
  vector<int> l(n);
  vector<int> r(n);

  int ans = 0;

  for(int i=0; i<n; ++i){
    cin >> t[i] >> l[i] >> r[i];
  }

  for(int i=0; i<n-1; ++i){
    for(int j=i+1; j<n; ++j){
      bool t1start = false;
      bool t1end = false;
      bool t2start = false;
      bool t2end = false;
      if(t[i] == 1 || t[i] == 2) t1start = true;
      if(t[i] == 1 || t[i] == 3) t1end = true;
      if(t[j] == 1 || t[j] == 2) t2start = true;
      if(t[j] == 1 || t[j] == 3) t2end = true;

      if(r[i] < l[j] || r[j] < l[i]) continue;

      if(r[i] == l[j]){
        if(t1end && t2start) ans++;
        else continue;
      } else if (r[j] == l[i]){
        if(t2end && t1start) ans++;
        else continue;
      } else {
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int H,W,A,B;

int did[16][16];
int ret=0;

void dfs(int y,int x,int A,int B) {
	if(A<0||B<0) return;
	if(x==W) {
		dfs(y+1,0,A,B);
		return;
	}
	if(y==H) {
		ret++;
		return;
	}
	
	if(did[y][x]) {
		dfs(y,x+1,A,B);
	}
	else {
		if(B) {
			did[y][x]=1;
			dfs(y,x+1,A,B-1);
			did[y][x]=0;
		}
		if(A) {
			if(x+1<W&&did[y][x+1]==0) {
				did[y][x]=did[y][x+1]=1;
				dfs(y,x+2,A-1,B);
				did[y][x]=did[y][x+1]=0;
			}
			if(y+1<H&&did[y+1][x]==0) {
				did[y][x]=did[y+1][x]=1;
				dfs(y,x+1,A-1,B);
				did[y][x]=did[y+1][x]=0;
			}
		}
	}
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>A>>B;
	
	dfs(0,0,A,B);
	
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
