#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(x,y) for(int x = 0;x < (y);x++) #define LLI long long int #define FORR(x,arr) for(auto& x:arr) #define ALL(a) (a.begin()),(a.end()) #define _L(x) cout<<(x)< class UF { public: vector _parent,_rank; UF() { _parent=_rank=vector(um,0); for(int i=0;i_rank[yRoot]) { _parent[xRoot] = yRoot; return yRoot; } if(_rank[xRoot]<_rank[yRoot]) { _parent[yRoot] = xRoot; return xRoot; } if(xRoot != yRoot) { _parent[yRoot] = xRoot; _rank[xRoot]++; return xRoot; } return xRoot; } }; int upperValue = 100000000; int dp[31]; vector V(4); int calculate(int rest, int a, int b, int c) { if(rest < 0) { return upperValue; } if(rest == 0) { return 0; } if(dp[rest] > 0) { return dp[rest]; } int minValue = upperValue; minValue = min(minValue, calculate(rest - a, a, b, c) + 1); minValue = min(minValue, calculate(rest - b, a, b, c) + 1); minValue = min(minValue, calculate(rest - c, a, b, c) + 1); dp[rest] = minValue; return minValue; } int main() { FOR(i, 4) { cin >> V[i]; } sort(V.begin(), V.end()); int minCost = upperValue; for(int a = 1; a <= 28;a++) { for(int b = a + 1;b <= 29;b++) { for(int c = b + 1;c <= 30;c++) { FOR(i, 31) { dp[i] = -1; } int sum = 0; for(int i = 3;i >= 0;i--) { int r = calculate(V[i], a, b, c); sum += r; } minCost = min(minCost, sum); } } } cout << minCost << endl; return 0; }