#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c, d, t = 0;
  cin >> a >> b >> c >> d;
  long long big, mid, smal;
  big = max(max(a, b), max(b, c));
  smal = min(min(a, b), min(b, c));
  if (smal < a && big > a)
    mid = a;
  else if (smal < b && big > b)
    mid = b;
  else if (smal < c && big > c)
    mid = c;
  else if (smal <= a && big >= a)
    mid = a;
  else if (smal <= b && big >= b)
    mid = b;
  else if (smal <= c && big >= c)
    mid = c;
  if (smal == mid)
    t += d;
  else if (d > abs(smal - mid))
    t += d - abs(smal - mid);
  if (big == mid)
    t += d;
  else if (d > abs(big - mid))
    t += d - abs(big - mid);
  cout << t << endl;
  return 0;
}
