#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int n, ans, sum, a, b, arr[100005];
string str;
int main() {
  ios::sync_with_stdio(false);
  {
    for (int i = 0; i < 3; i++) {
      cin >> arr[i];
    }
    cin >> n;
    sort(arr, arr + 3);
    if (arr[1] - arr[0] < n) {
      ans += (n - (arr[1] - arr[0]));
    }
    if (arr[2] - arr[1] < n) {
      ans += (n - (arr[2] - arr[1]));
    }
    cout << ans;
  }
  return 0;
}
