#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  vector<int> arr(3);
  arr[0] = a;
  arr[1] = b;
  arr[2] = c;
  sort(arr.begin(), arr.end());
  a = arr[0];
  b = arr[1];
  c = arr[2];
  cout << max(0, d - abs(a - b)) + max(0, d - abs(b - c));
}
