#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_map>
#define N 2048
#define M 1000000007
using namespace std;
int main()
{
vector<int> v;
set<int> s;
int sum = 0;
for (int i = 0; i < 4; i++) {
int x;
cin>>x;
sum += x + 0;
s.insert(x);
v.push_back(x);
}
sort(v.begin(), v.end());
if (s.size() == 1) cout<<0<<endl;
else if (s.size() == 2) {
if (v[0] == v[1] && v[2] == v[3]) cout<<2 * (v[2] - v[0])<<endl;
else if (v[0] == v[1]) {
cout<<(v[3] - v[0])<<endl;
} else {
cout<<(v[0] - v[3])<<endl;
}
} else if (s.size() == 3) {
if (v[0] == v[1]) cout<<v[2] - v[0] + v[3] - v[0]<<endl;
else if (v[2] == v[1]) cout<<v[2] - v[0] + v[3] - v[2]<<endl;
else cout<<v[2] - v[0] + v[2] - v[1]<<endl;
} else {
int div = sum / 4;
int ans = abs(v[0] - div) + abs(v[1] - div) + abs(v[2] - div) + abs(v[3] - div);
div++;
ans = min(ans, abs(v[0] - div) + abs(v[1] - div) + abs(v[2] - div) + abs(v[3] - div));
cout<<ans<<endl;
}
}