#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  vi seq(3);
  int d;
  cin >> seq[0] >> seq[1] >> seq[2] >> d;
  sort(seq.begin(), seq.end());
  cout << max(0, d - (seq[1] - seq[0])) + max(0, d - (seq[2] - seq[1])) << '\n';
  return 0;
}
