#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; } } } } stringstream ss; ss << ans; P(ss.str()); return 0; }