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