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