#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <random>
#include <chrono>

/* #include <atcoder/all> */
/* using namespace atcoder; */
using namespace std;

void debug_out(){ cout << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
/* const ll MOD = 998244353; */
const ll INF = (1<<30)-1;
const ll INFLL = 1ll<<60;
const double PI = acos(-1);

struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int sx, sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;

  if(sx == gx) cout << sx << "\n";
  else{
    int x = gx-sx;
    int y = sy+gy;

    ld t = (ld)x/y;
    cout << t*sy+sx << "\n";
  }

  return 0;
}

  #include <bits/stdc++.h>
  using namespace std;
  #define rep(i, n) for(int i = 0; i < n; ++i)
  #define ll long long
  template <typename T>
  bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;}

  const ll MOD = 1e9+7;
  const ll LINF = 1001002003004005006ll;
  const int INF = 1001001001;
  long long Comb(ll n, ll i){long long ans = 1; if(i>n || i < 0) return 0; if(i == 0 || i == n) return 1; else {for(int j = 1; j <= i; ++j){ans *=(n+1-j); ans /= j;} }return ans;}
  template<typename T> T gcd(T a, T b){if(b == 0) return a;else return gcd(b, a%b);}
  template<typename T> T lcm(T a, T b){if(b > a) swap(a, b); T g = gcd(a, b);return a / g * b;}

void solve(){
  int n; cin >> n;
  vector<pair<double, double>> inter;
  rep(i, n) {
    double t, a, b;
    cin >> t >> a >> b;
    if(t == 1) inter.push_back(make_pair(a, b));
    else if(t == 2) inter.push_back(make_pair(a, b-0.1));
    else if(t == 3) inter.push_back(make_pair(a+0.1, b));
    else inter.push_back(make_pair(a+0.1, b-0.1));
  }
  sort(inter.begin(), inter.end());
  int ans = 0;
  for(int i = 0; i < n-1; ++i) {
    //if(inter[i].first > inter[i].second) continue;
    double end = inter[i].second;
    for(int j = i + 1; j < n; ++j) {
      //if(inter[j].first > inter[j].second) continue;
      double start = inter[j].first;
      if(start <=  end) {
        ans++;
        //cout << i << " "  << j << endl;
      }
    }
  }
  cout << ans << endl;
}

  int main(void){
    solve();
    return 0;
  }