#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int x, d, i;
  vector<long long> v;
  for (i = 0; i < 3; i++) {
    cin >> x;
    v.push_back(x);
  }
  cin >> d;
  sort(v.begin(), v.end());
  long long int ans = 0;
  ans = max((long long)0, d - (v[1] - v[0]));
  ans += max((long long)0, d - (v[2] - v[1]));
  cout << ans;
  return 0;
}
