#include <bits/stdc++.h>
using namespace std;
long long t, d, a[10], res1, res2, sum, jem;
int main() {
  for (int i = 1; i <= 3; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + 4);
  cin >> d;
  if (abs(a[1] - a[2]) < d) {
    sum += abs(d - abs(a[1] - a[2]));
  }
  if (abs(a[2] - a[3]) < d) {
    sum += abs(d - abs(a[2] - a[3]));
  }
  cout << sum;
}
