#include <bits/stdc++.h>
using namespace std;
const long long int INF = 9223372036854775807;
const long long int mod = 1000000007;
const long long int zero = 0;
using namespace std;
int main() {
  vector<long long> a(3);
  long long d;
  cin >> a[0] >> a[1] >> a[2] >> d;
  sort(a.begin(), a.end());
  cout << max(a[0] - a[1] + d, (long long int)0) +
              max(a[1] + d - a[2], (long long int)0);
}
