#include <bits/stdc++.h>
using namespace std;
int main() {
  int a1 = {};
  int b = {};
  int c = {};
  scanf("%d %d %d", &a1, &b, &c);
  int a[3] = {a1, b, c};
  int d = {};
  int sum = 0;
  scanf("%d", &d);
  for (int i = 0; i <= 1; i++) {
    for (int j = i; j <= 1; j++) {
      if (a[j] > a[j + 1]) {
        swap(a[j], a[j + 1]);
      }
    }
  }
  sort(a, a + 3);
  if (abs(a[1] - a[0]) < d) {
    sum += d - abs(a[1] - a[0]);
  }
  if (abs(a[1] - a[2]) < d) {
    sum += d - abs(a[1] - a[2]);
  }
  cout << sum;
  return 0;
}
