B[999],V[4],X[3],T,R,i,j,r;main(){ for(i=0;i<4;i++)scanf("%d",&V[i]),T+=V[i];R=T; for(X[0]=1;X[0]<=30;X[0]++)for(X[1]=X[0]+1;X[1]<=30;X[1]++)for(X[2]=X[1]+1;X[2]<=30;X[2]++){ for(j=0;j<=T;j++)B[j]=!j; for(i=0;i<3;i++)for(int j=X[i];j<=T;j++)if(B[j-X[i]]&&(!B[j]||B[j]>B[j-X[i]]))B[j]=B[j-X[i]]+1; for(i=r=0;i<4&&B[V[i]];)r+=B[V[i++]]-1; if(i==4&&R>r)R=r; } R=!printf("%d\n",R); }