#include using namespace std; namespace { typedef double real; typedef long long ll; template ostream& operator<<(ostream& os, const vector& vs) { if (vs.empty()) return os << "[]"; auto i = vs.begin(); os << "[" << *i; for (++i; i != vs.end(); ++i) os << " " << *i; return os << "]"; } template istream& operator>>(istream& is, vector& vs) { for (auto it = vs.begin(); it != vs.end(); it++) is >> *it; return is; } const int INF = 1<<28; vector xs; void input() { xs.resize(4); cin >> xs; } int cache[31][31][31][31]; int f(int v, int a, int b, int c) { if (v < 0) return INF; if (v == 0) return 0; int& x = cache[v][a][b][c]; if (x >= 0) return x; return x = min(f(v - c, a, b, c) + 1, min(f(v - a, a, b, c) + 1, f(v - b, a, b, c) + 1)); } int calc(int a, int b, int c) { int ans = 0; for (int i = 0; i < 4; i++) { ans += f(xs[i], a, b, c); } return ans; } void solve() { int ans = INF; sort(xs.begin(), xs.end()); memset(cache, -1, sizeof(cache)); for (int a = 1; a <= 30; a++) { for (int b = a + 1; b <= 30; b++) { for (int c = b + 1; c <= 30; c++) { ans = min(ans, calc(a, b, c)); } } } cout << ans << endl; } } int main() { input(); solve(); return 0; }