#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long int a, b, c, d, max1, max2, max3, s = 0;
  cin >> a >> b >> c >> d;
  max1 = max(max(a, b), c);
  max3 = min(min(a, b), c);
  max2 = a + b + c - max1 - max3;
  if ((d > max1 - max2)) s = s + d - (max1 - max2);
  if (d > (max2 - max3)) s = s + d - (max2 - max3);
  cout << s << endl;
}
