#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c, d, temp, kqua = 0;
  cin >> a >> b >> c >> d;
  if (a > b) {
    temp = b;
    b = a;
    a = temp;
  }
  if (a <= c && c <= b) {
    temp = c;
    c = b;
    b = temp;
  } else if (a > c) {
    temp = c;
    c = b;
    b = a;
    a = temp;
  }
  if (b <= d + a) kqua = d - b + a;
  if (c <= d + b) kqua = kqua + d - c + b;
  cout << kqua;
  return 0;
}
