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