#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } const ll inf = 1e+18; struct edge{ int from, to; ll cost; edge(int from, int to, ll cost): from(from), to(to), cost(cost) {} }; //return //true:if nagetive loop does not exist //false:if negative loop exists //d:result bool bellmanford(vector es, vector &d, int s){ int n = d.size(); for(int i = 0; i < n; i++){ d[i] = inf; } d[s] = 0; int cnt_loop = 0; while(true){ cnt_loop++; bool update = false; for(int i = 0; i < es.size(); i++){ edge e = es[i]; if(d[e.from] != inf && d[e.from]+e.cost < d[e.to]){ d[e.to] = d[e.from]+e.cost; update = true; } } if(!update) { return true; } else if(cnt_loop >= n) { return false; } } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; ll a, b, c, d, e; cin >> a >> b >> c >> d >> e; auto judge = [&](ll x){ vector es; for(int i = 0; i < 5; i++) es.push_back(edge(i+1, i, 0)); es.push_back(edge(3, 1, a-x)); es.push_back(edge(4, 2, b-x)); es.push_back(edge(0, 3, c)); es.push_back(edge(1, 4, d)); es.push_back(edge(2, 5, e)); vector d(6); return bellmanford(es, d, 0); }; ll l = 0, r = 1e16; while(r-l > 1){ ll x = (l+r)/2; if(judge(x)) { l = x; }else{ r = x; } } cout << l << endl; }