#include <bits/stdc++.h>
using namespace std;
int main() {
  int in[3], d;
  cin >> in[0] >> in[1] >> in[2] >> d;
  sort(in, in + 3);
  int r1 = d - abs(in[0] - in[1]);
  int r2 = d - abs(in[1] - in[2]);
  int res = 0;
  if (r1 > 0) {
    res += r1;
  }
  if (r2 > 0) {
    res += r2;
  }
  cout << res;
  return 0;
}
