#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long int arr[3] = {0};
  for (long long int i = 0; i < 3; i++) cin >> arr[i];
  long long int d = 0;
  cin >> d;
  sort(arr, arr + 3);
  long long int ans = 0;
  for (long long int i = 1; i < 3; i++) {
    if (arr[i] - arr[i - 1] < d) ans += d - abs(arr[i] - arr[i - 1]);
  }
  cout << ans << endl;
  return 0;
}
