#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans = 0;
void Main(){
    using P = pair<int, int>;
    int a, b, x, y;
    cin >> a >> b >> x >> y;
    a--;
    b--;
    vector<vector<P>> graph(200);
    For(i,0,100){
        graph[i].push_back({i + 100, x});
        graph[i + 100].push_back({i , x});
    }
    For(i,0,99){
        graph[i + 1].push_back({i + 100, x});
        graph[i + 100].push_back({i + 1 , x});
    }
    For(i,0,99){
        graph[i].push_back({i + 1, y});
        graph[i + 1].push_back({i, y});
        graph[i + 100].push_back({i + 101, y});
        graph[i + 101].push_back({i + 100, y});
    }
    vector<int> dist(200, 1e9);
    dist[a] = 0;
    stack<P> st;
    st.push({a , 0});
    while(!st.empty()){
        auto [now, d] = st.top();
        st.pop();
        for(auto to : graph[now]){
            if(dist[to.first] > d + to.second){
                dist[to.first] = d + to.second;
                st.push({to.first, dist[to.first]});
            }
        }
    }
    cout << dist[b + 100] << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#define mk make_pair
#define pp pair<int, int>
ll MOD = 1000000007;
ll mod = 998244353;
int inf = 2000001000;
ll INF = 1e18 + 5;

int main() {
    int n;
    cin >> n;
    vector<pair<ld,ld>> a(n);
    rep(i,n){
        ld f,g,h;
        cin >> f >> g >> h;
        if (f==1) a[i]=mk(g,h);
        if (f==2) a[i]=mk(g,h-0.1);
        if (f==3) a[i]=mk(g+0.1,h);
        if (f==4) a[i]=mk(g+0.1,h-0.1);
    }
    int ans=0;
    rep(i,n){
        for (int j=i+1;j<n;j++){
            if (!(a[i].first>a[j].second || a[i].second<a[j].first)) {ans++;}
        }
    }
    cout << ans << endl;
}
