#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[4], d;
  for (int i = 0; i < 3; i++) cin >> a[i];
  cin >> d;
  sort(a, a + 3);
  int sum = 0;
  if (a[2] - a[1] >= d)
    sum += 0;
  else
    sum += d - (a[2] - a[1]);
  if (a[1] - a[0] >= d)
    sum += 0;
  else
    sum += d - (a[1] - a[0]);
  cout << sum << endl;
  return 0;
}
