#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long a[4];
  cin >> a[0] >> a[1] >> a[2] >> a[3];
  sort(a, a + 3);
  long long p = 0;
  long long q = 0;
  q = abs(a[0] - a[1]);
  if (q < a[3]) {
    p += (a[3] - q);
  }
  q = abs(a[1] - a[2]);
  if (q <= a[3]) {
    p += (a[3] - q);
  }
  cout << p << endl;
  return 0;
}
