#include <bits/stdc++.h>
using namespace std;
int _abs(int n) { return n > 0 ? n : -n; }
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int man[3], D;
  cin >> man[0] >> man[1] >> man[2] >> D;
  sort(man, man + 3);
  int dist = 0;
  int t = _abs(man[1] - man[0]);
  if (t < D) dist += _abs(D - t);
  t = _abs(man[2] - man[1]);
  if (t < D) dist += _abs(D - t);
  cout << dist << "\n";
  return 0;
}
