#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[100], d;
  scanf("%d %d %d %d", &a[1], &a[2], &a[3], &d);
  sort(a + 1, a + 3 + 1);
  int ans = 0;
  int s1 = a[2] - a[1];
  int s2 = d - s1;
  if (s2 > 0) ans = ans + s2;
  s1 = a[3] - a[2];
  s2 = d - s1;
  if (s2 > 0) ans = ans + s2;
  printf("%d", ans);
}
