// #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include using namespace std; using namespace atcoder; using mint = modint998244353; // using mint = modint1000000007; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair; using pll = pair; using T = tuple; using G = vector>; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep2(i, a, b) for (ll i = a; i < (b); ++i) #define rrep2(i, a, b) for (ll i = a-1; i >= (b); --i) #define rep3(i, a, b, c) for (ll i = a; i < (b); i+=c) #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define popcount __builtin_popcount #define popcountll __builtin_popcountll #define fi first #define se second #define UNIQUE(v) sort(rng(v)), v.erase(unique(rng(v)), v.end()) #define MIN(v) *min_element(rng(v)) #define MAX(v) *max_element(rng(v)) #define SUM(v) accumulate(rng(v),0) #define IN(v, x) (find(rng(v),x) != v.end()) template bool chmin(T &a,T b){if(a>b){a=b;return 1;}else return 0;} template bool chmax(T &a,T b){if(a void printv(vector &v){rep(i,v.size())cout< void printvv(vector> &v){rep(i,v.size())rep(j,v[i].size())cout< extgcd(ll a, ll b) { if (b == 0) return {a, 1, 0}; ll g, x, y; tie(g, x, y) = extgcd(b, a%b); return {g, y, x-a/b*y}; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); vector vs(4); rep(i, 4) cin >> vs[i]; int ans = INF; rep2(i, 1, 31)rep2(j, i+1, 31)rep2(k, j+1, 31){ int g = gcd(gcd(i, j), k); bool flag = false; for (auto v: vs) if (v%g){ flag = true; break; } if (flag) continue; int x = i/g, y = j/g, z = k/g; int res = 0; bool ok = true; for(auto v: vs){ v /= g; int tmp = INF; for(int c = 0; c <= v/z; c++){ for(int b = 0; b <= v/y; b++){ int d = v-c*z-b*y; if (d < 0) break; if (d%x) continue; chmin(tmp, d/x+b+c); } } if (tmp == INF){ ok = false; break; } res += tmp; } if (ok) chmin(ans, res); } cout << ans << endl; return 0; }