#include #include #include #include #include #include #include #include #include // require sort next_permutation count __gcd reverse etc. #include // require abs exit atof atoi #include // require scanf printf #include #include // require accumulate #include // require fabs #include #include #include #include // require setw #include // require stringstream #include // require memset #include // require tolower, toupper #include // require freopen #include // require srand #define rep(i,n) for(int i=0;i<(n);i++) #define ALL(A) A.begin(), A.end() #define INF 1<<20 /* No.27 板の準備 全探索、全探索? */ using namespace std; typedef long long ll; typedef pair P; int main() { ios_base::sync_with_stdio(0); vector V(4, 0 ); rep (i, 4 ) cin >> V[i]; vector order(4, 0 ); rep (i, 4 ) order[i] = i; int res = INF; do{ vector cand (3, 0 ); rep (i, 3 ) cand[i] = V[order[i]]; int to = V[order[3]]; for (int x = 0; x <= to/cand[0]; x++ ){ for (int y = 0; y <= to/cand[1]; y++ ){ for (int z = 0; z <= to/cand[2]; z++ ){ if (x*cand[0] + y*cand[1] + z*cand[2] == to ){ /* rep (i, 3 ){ cerr << "cand: " << cand[i] << endl; } // end rep cerr << "to: " << to << endl; cerr << "x: " << x << " y: " << y << " z: " << z << endl; */ res = min (res, x + y + z + 3 ); } // end if } // end for } // end for } // end for }while (next_permutation (ALL (order ) ) ); cout << res << endl; return 0; }