#include <bits/stdc++.h>
using namespace std;
int main() {
  long a, b, c, d;
  cin >> a >> b >> c >> d;
  vector<long> v;
  v.push_back(a);
  v.push_back(b);
  v.push_back(c);
  sort(v.begin(), v.end());
  long max, min, mid;
  max = v[2];
  mid = v[1];
  min = v[0];
  long diff1 = mid - min;
  long diff2 = max - mid;
  if (diff1 >= d && diff2 >= d)
    cout << "0" << endl;
  else if (diff1 >= d)
    cout << (d - diff2) << endl;
  else if (diff2 >= d)
    cout << (d - diff1) << endl;
  else {
    long sum = 2 * d - diff1 - diff2;
    cout << sum << endl;
  }
}
