#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

const long long MOD = 1000000007;

int main(){
  long double ax,ay,bx,by;
  cin >> ax >> ay >> bx >> by;
  if(ax==bx) cout << ax << endl;
  else{
    cout << fixed << setprecision(10);
    if(ax<bx){
	    cout<<ax+(bx-ax)*(ay/(ay+by))<<endl;
    }
    else{
	    cout<<bx+(ax-bx)*(by/(ay+by))<<endl;
    }
  }
  
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int n;
vector<int> t,l,r;

void solve() {
  ll ans = 0;
  REP(i,n) {
    int left = l[i], right = r[i];
    int left_kai = 0, right_kai = 0;
    if (t[i] == 1) {
    } else if (t[i] == 2) {
      right_kai = 1;
    } else if (t[i] == 3) {
      left_kai = 1;
    } else {
      right_kai = 1;
      left_kai = 1;
    }

    for(int j = i+1; j < n; j++) {
      int leftj = l[j], rightj = r[j];

      int leftj_kai = 0, rightj_kai = 0;
      if (t[j] == 1) {
      } else if (t[j] == 2) {
        rightj_kai = 1;
      } else if (t[j] == 3) {
        leftj_kai = 1;
      } else {
        rightj_kai = 1;
        leftj_kai = 1;
      }

      if (right_kai && leftj_kai) {
        if (right <= leftj) continue;
      }
      if (!right_kai && leftj_kai) {
        if (right <= leftj) continue;
      }
      if (right_kai && !leftj_kai) {
        if (right <= leftj) continue;
      }
      if (!right_kai && !leftj_kai) {
        if (right < leftj) continue;
      }

      if (rightj_kai && left_kai) {
        if (rightj <= left) continue;
      }
      if (!rightj_kai && left_kai) {
        if (rightj <= left) continue;
      }
      if (rightj_kai && !left_kai) {
        if (rightj <= left) continue;
      }
      if (!rightj_kai && !left_kai) {
        if (rightj < left) continue;
      }

      ans++;
    }
  }

  cout << ans << endl;
  return;
}

int main() {
  cin >> n;
  t.resize(n);
  l.resize(n);
  r.resize(n);
  REP(i,n) cin >> t[i] >> l[i] >> r[i];

  solve();
  return 0;
}