#include using namespace std; template Value unboundedKnapsack(const vector& maxWeight, const vector& weight, const vector& value) { constexpr Value IMP = numeric_limits::min() + 1; const Weight mx = *max_element(maxWeight.begin(), maxWeight.end()); vector dp(mx + Weight(1)); if (strict) fill(dp.begin() + 1, dp.end(), IMP); for (size_t i = 0; i < weight.size(); ++i) { for (int w = 0; w <= mx; ++w) { if (strict && dp[w] == IMP) continue; Weight ww = Weight(w) + weight[i]; Value vv = dp[w] + value[i]; if (ww <= mx && dp[ww] < vv) dp[ww] = vv; } } Value res = 0; for (const auto& w : maxWeight) { if (dp[w] == IMP) return IMP; res += dp[w]; } return res; } template Value unboundedKnapsack(Weight maxWeight, const vector& weight, const vector& value) { return unboundedKnapsack({maxWeight}, weight, value); } template vector knapsackCount(Weight maxWeight, const vector& weight) { vector dp(maxWeight + Weight(1)); dp[0] = 1; for (auto& w : weight) { for (int i = 0; i <= maxWeight; ++i) { Weight ww = Weight(i) + w; if (ww <= maxWeight) dp[ww] += dp[i]; } } return dp; } template vector unboundedKnapsackFill(Weight maxWeight, const vector& weight) { vector dp(maxWeight + Weight(1)); dp[0] = true; for (auto& w : weight) { for (int i = 0; i <= maxWeight; ++i) { Weight ww = Weight(i) + w; if (ww <= maxWeight && dp[i]) dp[ww] = true; } } return dp; } int main() { vector v(4); for (int& i : v) cin >> i; sort(v.begin(), v.end()); vector a(3), b(3, -1); int res = numeric_limits::max(); for (a[0] = 1; a[0] <= v.back(); ++a[0]) { for (a[1] = a[0] + 1; a[1] <= v.back(); ++a[1]) { for (a[2] = a[1] + 1; a[2] <= v.back(); ++a[2]) { res = min(res, -unboundedKnapsack(v, a, b)); } } } cout << res << endl; }