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