#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n;
int main() {
  long long a, b, c, d;
  scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
  long long ar[] = {a, b, c};
  sort(ar, ar + 3);
  long long x = ar[1] + d;
  long long y = ar[1] - d;
  long long ans = 0;
  if (ar[0] > y) ans += abs(ar[0] - y);
  if (ar[2] < x) ans += abs(ar[2] - x);
  cout << ans << endl;
}
