#include <bits/stdc++.h>
using namespace std;
long long l = (1LL << 60);
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, a[5], i, j, sec = 0, d;
  cin >> a[0] >> a[1] >> a[2] >> d;
  sort(a, a + 3);
  if (abs(a[0] - a[1]) < d) {
    sec = d - abs(a[0] - a[1]);
  }
  if (abs(a[1] - a[2]) < d) {
    sec += d - abs(a[1] - a[2]);
  }
  cout << sec << '\n';
  return 0;
}
