#include <bits/stdc++.h>
using namespace std;
int main()
{
int a[3];
\!h int count = 0;
int d;
for (int i = 0; i < 3; i++)
cin >> a[i];
cin >> d;
sort(a, a + 3);
while (1)
{
while (a[1] - a[0] < d)
{
a[0]--;
count++;
}
while (a[2] - a[1] < d)
{
a[2]++;
count++;
}
break;
}
cout << count << endl;
}