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