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