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