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