#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int d, diff1, diff2, sum = 0, i;
  int a[3];
  for (i = 0; i < 3; i++) {
    cin >> a[i];
  }
  cin >> d;
  sort(a, a + 3);
  diff1 = abs(a[1] - a[0]);
  diff2 = abs(a[2] - a[1]);
  if (diff1 < d) {
    sum += d - diff1;
  }
  if (diff2 < d) {
    sum += d - diff2;
  }
  cout << sum;
  return 0;
}
