#include <bits/stdc++.h>
using namespace std;
long long mult(long long a, long long b, long long p = 1e9 + 7) {
  return ((a % p) * (b % p)) % p;
}
long long multbig(long long a, long long b, long long mod = 1e9 + 7) {
  if (a == 0 or b == 0) return 0;
  if (a == 1 or b == 1) return (a * b) % mod;
  long long cur = multbig(a, b / 2, mod);
  cur = (2 * cur) % mod;
  if (b % 2) cur = (cur + a) % mod;
  return cur;
}
long long add(long long a, long long b, long long p = 1e9 + 7) {
  if (a >= p) a %= p;
  if (b >= p) b %= p;
  if (a + b > p)
    return (a + b) % p;
  else
    return a + b;
}
long long sub(long long a, long long b, long long p = 1e9 + 7) {
  return (a % p - b % p + p) % p;
}
long long fpow(long long n, long long k, long long p = 1e9 + 7) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = mult(r, n, p);
    n = mult(n, n, p);
  }
  return r;
}
long long inv(long long a, long long p = 1e9 + 7) { return fpow(a, p - 2, p); }
long long inv_euclid(long long a, long long m = 1e9 + 7) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
int isPowerof2(long long x) { return (x && !(x & x - 1)); }
long long log2(long long x) {
  long long res = 0;
  while (x >>= 1) res++;
  return res;
}
bool isPerfectSquare(long double x) {
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);
}
vector<long long> adj[200005];
long long update[200005];
int binaryToDecimal(string n) {
  string num = n;
  int dec_value = 0;
  int base = 1;
  int len = num.length();
  for (int i = len - 1; i >= 0; i--) {
    if (num[i] == '1') dec_value += base;
    base = base * 2;
  }
  return dec_value;
}
int main() {
  int a[3], d;
  for (int i = 0; i < 3; i++) cin >> a[i];
  cin >> d;
  sort(a, a + 3);
  cout << max(0, d - (a[1] - a[0])) + max(0, d - (a[2] - a[1])) << "\n";
}
