#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  if (b > c) swap(b, c);
  if (a > b) swap(a, b);
  if (b > c) swap(b, c);
  if (b - a >= d) {
    if (c - b >= d) return puts("0");
    printf("%d\n", d - (c - b));
    return 0;
  }
  if (c - b >= d) {
    printf("%d\n", d - (b - a));
    return 0;
  }
  printf("%d\n", d - (b - a) + d - (c - b));
}
