#define _USE_MATH_DEFINES #include #include #include #include #include //#include #include #include #include #include #include #include ///////// #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define P(p) cout<<(p)< ///////// typedef long long LL; typedef long double LD; ///////// using namespace::std; ///////// int solve(int V,int A,int B,int C){ int ans = -1; if(V < A){ return -1; } for(int a=0;a<=V/A;++a){ for(int b=0; b<=V/B;++b){ if( V < a*A+b*B){ break; } for(int c=0; c<=V/C;++c){ if( V == a*A+b*B+c*C ){ if( ans == -1 || ans > a+b+c){ ans = a+b+c; } }else if( V < a*A+b*B+c*C){ break; } } } } return ans; } int main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed;// //cout << setprecision(10);// int H,I,J,K; cin>>H>>I>>J>>K; int HH,II,JJ,KK; int ans=-1,tans; for(int i=1;i<=28;++i){ for(int j=i+1;j<=29;++j){ for(int k=j+1;k<=30;++k){ ///// /* HH = solve(H,i,j,k);if(HH==-1)continue; II = solve(I,i,j,k);if(II==-1)continue; JJ = solve(J,i,j,k);if(JJ==-1)continue; KK = solve(K,i,j,k);if(KK==-1)continue; tans = HH+II+JJ+KK; if(ans == -1 || ans > tans){ ans = tans; } */ ///// int dp[100]; rep(count,31)dp[count]=0; dp[0]=1; rep(count,31){ if(dp[count] != 0){ dp[count+i] = dp[count+i]>0?min( dp[count+i],dp[count]+1 ):dp[count]+1; dp[count+j] = dp[count+j]>0?min( dp[count+j],dp[count]+1 ):dp[count]+1; dp[count+k] = dp[count+k]>0?min( dp[count+k],dp[count]+1 ):dp[count]+1; } } if(dp[H] != 0 && dp[I] != 0 && dp[J] != 0 && dp[K] != 0){ tans = dp[H] + dp[I] + dp[J] + dp[K] -4 ; if(ans == -1 || ans > tans){ ans = tans; } } ///// } } } stringstream ss; ss << ans; P(ss.str()); return 0; }