#include #include #include #include #include #define V1I vector #define V2I vector< vector > #define V3I vector< vector< vector > > #define V4I vector< vector< vector< vector > > > using namespace std; const int INF = 1e8; int main() { int v1, v2, v3, v4; cin >> v1 >> v2 >> v3 >> v4; int max_v = max(max(v1, v2), max(v3, v4)); V4I dp; dp.assign(31, V3I(31, V2I(31, V1I(61, INF)))); int a, b, c, len, x; for (a = 1; a <= max_v; a++) { for (b = a; b <= max_v; b++) { for (c = b; c <= max_v; c++) { dp[a][b][c][a] = 1; dp[a][b][c][b] = 1; dp[a][b][c][c] = 1; for (len = a; len <= max_v; len++) { x = dp[a][b][c][len]; if (x < INF) { dp[a][b][c][len + a] = min(dp[a][b][c][len + a], x + 1); dp[a][b][c][len + b] = min(dp[a][b][c][len + b], x + 1); dp[a][b][c][len + c] = min(dp[a][b][c][len + c], x + 1); } } } } } int ans = INF; for (a = 1; a <= max_v; a++) { for (b = a; b <= max_v; b++) { for (c = b; c <= max_v; c++) { ans = min(ans, dp[a][b][c][v1] + dp[a][b][c][v2] + dp[a][b][c][v3] + dp[a][b][c][v4]); } } } cout << ans << endl; return 0; }