#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, c, d;
  long long int arr[3];
  cin >> arr[0] >> arr[1] >> arr[2] >> d;
  sort(arr, arr + 3);
  a = arr[0];
  b = arr[1];
  c = arr[2];
  long long int ans = 0;
  if (a > b - d) ans += abs(a - (b - d));
  if (c < b + d) ans += abs(c - (b + d));
  cout << ans;
}
