#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define ve vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define all(v) (v).begin(), (v).end()
#define sortve(v) sort(all(v))
#define rsrt(v) sort(v.rbegin(), v.rend())
#define rev(i, n) for (ll i = n - 1; i >= 0; i--)
#define f(i, n) for (ll i = 0; i < n; i++)
#define f1(i, n) for (ll i = 1; i < n + 1; i++)
#define f2(i, a, b) for (ll i = a; i < b; i++)
#define precision(x) cout << fixed << setprecision(x);
#define testcase \
    ll t;        \
    cin >> t;    \
    while (t--)
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(nullptr);             \
    cout.tie(nullptr)
#define bas cout << "\n";
const ll PI = 3.1415926535897932384626;
const ll mod = 1000000007;
const ll FMOD = 998244353;
const ll N = 100005;
const double eps = 1e-9;

// Let's Go 😇

int main()
{
    double a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a > c)
    {
        swap(a, c);
        swap(b, d);
    }
    //cout << a << b << c << d;
    double tan = (b + d) / (c - a);
    // cout << tan;
    double ans = a + (b / tan);
    precision(6);
    cout << ans;
}

/* SERIOUSLY, It ⬇ ain't a JOKE ⬇ */

/* The problem  is either 
   in conditional statements
   or the increments or %mod or
   endl or you are printing 
   something else*/
// ABC196C
// 幾何
// 各色ごとの最終位置は二択.

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

const int INF = 1e18;

signed main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int N;
  cin >> N;
  map<int, vector<int>> m;
  for (int i = 0; i < N; i++) {
    int x, c;
    cin >> x >> c;
    m[c].push_back(x);
  }
  vector<vector<int>> pos(N + 1, vector<int>(2, 0));
  vector<vector<int>> sec(N + 1, vector<int>(2, INF));
  sec[0] = {0, 0};
  int i = 0;
  for (auto& [_, v] : m ) {
    auto max = *max_element(v.begin(), v.end());
    auto min = *min_element(v.begin(), v.end());
    for (int j = 0; j < 2; j++) {
      // max first
      int tmp = abs(max - pos[i][j]) + max - min + sec[i][j];
      if (tmp < sec[i + 1][0]) {
        sec[i + 1][0] = tmp;
        pos[i + 1][0] = min;
      }
      int tmp2 = abs(pos[i][j] - min) + max - min + sec[i][j];
      if (tmp2 < sec[i + 1][1]) {
        sec[i + 1][1] = tmp2;
        pos[i + 1][1] = max;
      }
    }
    ++i;
  }
  cout << min(sec[i][0] + abs(pos[i][0]), sec[i][1] + abs(pos[i][1])) << endl;


  return 0;
}
