#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int M = 1e9 + 7;
long long a[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long d;
  cin >> a[0] >> a[1] >> a[2] >> d;
  sort(a, a + 3);
  cout << max(0ll, a[0] - a[1] + d) + max(0ll, a[1] + d - a[2]);
}
