#include <bits/stdc++.h>
using namespace std;
inline long long uscan() {
  long long n = 0, c = getchar();
  bool check = 0;
  while (c < '0' || c > '9') {
    if (c == '-') check = 1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    n = n * 10 + c - '0';
    c = getchar();
  }
  return check ? -n : n;
}
void prin(vector<long long> a) {
  for (auto it : a) cout << it << ' ';
  putchar('\n');
}
void prin(vector<vector<long long> > a) {
  for (auto vec : a) {
    for (auto it : vec) cout << it << ' ';
    putchar('\n');
  }
  putchar('\n');
}
void prin(vector<pair<long long, long long> > a) {
  for (auto it : a) cout << it.first << ' ' << it.second << '\n';
  putchar('\n');
}
int main() {
  long long t = 1;
  while (t--) {
    long long i, j, k;
    vector<long long> a(3);
    for (i = 0; i < 3; i++) a[i] = uscan();
    sort(a.begin(), a.end());
    long long d = uscan();
    cout << max(0LL, d - (a[1] - a[0])) + max(0LL, d - (a[2] - a[1])) << '\n';
  }
  return 0;
}
