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