#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 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){ int dp[100]; rep(count,31)dp[count]=1<<28; dp[0]=1; rep(count,31){ if(dp[count] != 0){ dp[count+i] = min( dp[count+i],dp[count]+1 ); dp[count+j] = min( dp[count+j],dp[count]+1 ); dp[count+k] = min( dp[count+k],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; }