#include using namespace std; #ifdef LOCAL #include "debug.h" #else #define DEBUG(...) #endif int main() { cin.tie(nullptr); ios::sync_with_stdio(false); using ll = long long; auto ts = [](ll l, ll r, auto f) { while (r - l > 2) { ll m = (l + r) / 2; if (f(m) < f(m + 1)) { l = m; } else { r = m + 1; } } return f(l + 1); }; ll a, b, c, d, e; cin >> a >> b >> c >> d >> e; auto g = [&](ll abe) { a -= abe; b -= abe; e -= abe; ll abc = min({a, b, c}); ll cde = min({c - abc, d, e}); ll bcd = min({b - abc, c - abc - cde, d - cde}); a += abe; b += abe; e += abe; return abe + abc + bcd + cde; }; auto f = [&](ll ade) { a -= ade; d -= ade; e -= ade; ll res = ts(-1, min({a, b, e}) + 1, g); a += ade; d += ade; e += ade; return ade + res; }; cout << ts(-1, min({a, d, e}) + 1, f) << '\n'; }