#pragma GCC optimize("Ofast") #include using namespace std; #ifdef __LOCAL #include #else #define debug(...) void(0) #endif #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() template istream& operator>>(istream&is,vector&v){ for(T&p:v)is>>p; return is; } template ostream& operator<<(ostream&os,const vector&v){ if(&os==&cerr)os<<"["; for(int i=0;i bool chmin(T &a,T b){ return (a>b&&(a=b,true)); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); vector v(4); cin>>v; int ans=INF; REP(c,31)if(c){ vector dp(31,INF); for(int i=0;i*c<=30;i++)dp[i*c]=i; REP(b,c)if(b){ auto dp2=dp; REP(i,31-b)chmin(dp2[i+b],dp2[i]+1); REP(a,b)if(a){ auto dp3=dp2; REP(i,31-a)chmin(dp3[i+a],dp3[i]+1); int sum=0; REP(i,4)sum+=dp3[v[i]]; chmin(ans,sum); } } } cout<