#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 100;
const int MOD = 1e9 + 7;
int a, b, c, d;
int p[5];
int main() {
  for (int i = 1; i <= 3; i++) cin >> p[i];
  cin >> d;
  sort(p + 1, p + 4);
  int d1 = p[2] - p[1];
  int d2 = p[3] - p[2];
  int ans = 0;
  if (d1 < d) ans += d - d1;
  if (d2 < d) ans += d - d2;
  cout << ans << endl;
  return 0;
}
