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