#include <bits/stdc++.h>
using namespace std;
long long a[3], b, c, x, y, z, ans, ans1, l;
vector<long long> v;
bool o;
int main() {
  cin >> a[0] >> a[1] >> a[2] >> b;
  sort(a, a + 3);
  c = a[1] - a[0] - b;
  l = a[2] - a[1] - b;
  if (c < 0 && l < 0)
    cout << abs(c + l);
  else if (c < 0)
    cout << abs(c);
  else if (l < 0)
    cout << abs(l);
  else
    cout << 0;
}
