#include #include #include #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) #define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i)) #define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x) typedef long long ll; using namespace std; template void setmin(T & a, T const & b) { if (b < a) a = b; } const int inf = 1e9+7; int main() { const int MAX = 30; int x, y, z, w; cin >> x >> y >> z >> w; ll ans = inf; repeat (c,MAX+1) { repeat (b,c) { repeat_from (a,1,b) { array dp; whole(fill, dp, inf); dp[0] = 0; repeat (i,MAX) { if (i+a < MAX+1) setmin(dp[i+a], dp[i] + 1); if (i+b < MAX+1) setmin(dp[i+b], dp[i] + 1); if (i+c < MAX+1) setmin(dp[i+c], dp[i] + 1); } setmin(ans, dp[x] + dp[y] + dp[z] + dp[w]); } } } cout << ans << endl; return 0; }