#include <bits/stdc++.h>
using namespace std;
const int N = 5e5;
const int LOG = 20;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<int> v(3);
  int a, b, c, d;
  for (int i = 0; i < 3; ++i) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  cin >> d;
  a = v[0], b = v[1], c = v[2];
  int ans = 0;
  if (abs(b - c) < d) ans += d - abs(b - c);
  if (abs(a - b) < d) ans += d - abs(a - b);
  cout << ans << "\n";
  return 0;
}
