//#define _GLIBCXX_DEBUG #include using namespace std; #define endl '\n' #define lfs cout<= (ll)(n); i--) using ll = long long; using ld = long double; const ll MOD1 = 1e9+7; const ll MOD9 = 998244353; const ll INF = 1e18; using P = pair; template bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;} template bool chmax(T1 &a,T2 b){if(a void ans(bool x,T1 y,T2 z){if(x)cout< void debug(vector>&v,ll h,ll w){for(ll i=0;i&v,ll h,ll w){for(ll i=0;i void debug(vector&v,ll n){if(n!=0)cout< vector>vec(ll x, ll y, T w){ vector>v(x,vector(y,w));return v;} ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;} vectordx={1,-1,0,0,1,1,-1,-1}; vectordy={0,0,1,-1,1,-1,1,-1}; template vector make_v(size_t a,T b){return vector(a,b);} template auto make_v(size_t a,Ts... ts){ return vector(a,make_v(ts...)); } template ostream &operator<<(ostream &os, const pair&p){ return os << p.first << " " << p.second; } //mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); template< typename flow_t > struct Dinic { const flow_t INF; struct edge { ll to; flow_t cap; ll rev; bool isrev; }; vector< vector< edge > > graph; vector< ll > min_cost, iter; Dinic(ll V) : INF(numeric_limits< flow_t >::max()), graph(V) {} void add_edge(ll from, ll to, flow_t cap) { graph[from].emplace_back((edge) {to, cap, (ll) graph[to].size(), false}); graph[to].emplace_back((edge) {from, 0, (ll) graph[from].size() - 1, true}); } bool bfs(ll s, ll t) { min_cost.assign(graph.size(), -1); queue< ll > que; min_cost[s] = 0; que.push(s); while(!que.empty() && min_cost[t] == -1) { ll p = que.front(); que.pop(); for(auto &e : graph[p]) { if(e.cap > 0 && min_cost[e.to] == -1) { min_cost[e.to] = min_cost[p] + 1; que.push(e.to); } } } return min_cost[t] != -1; } flow_t dfs(ll idx, const ll t, flow_t flow) { if(idx == t) return flow; for(ll &i = iter[idx]; i < graph[idx].size(); i++) { edge &e = graph[idx][i]; if(e.cap > 0 && min_cost[idx] < min_cost[e.to]) { flow_t d = dfs(e.to, t, min(flow, e.cap)); if(d > 0) { e.cap -= d; graph[e.to][e.rev].cap += d; return d; } } } return 0; } flow_t max_flow(ll s, ll t) { flow_t flow = 0; while(bfs(s, t)) { iter.assign(graph.size(), 0); flow_t f = 0; while((f = dfs(s, t, INF)) > 0) flow += f; } return flow; } void output() { for(ll i = 0; i < graph.size(); i++) { for(auto &e : graph[i]) { if(e.isrev) continue; auto &rev_e = graph[e.to][e.rev]; cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << e.cap + rev_e.cap << ")" << endl; } } } }; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll res=0,buf=0; bool judge = true; vectora(5); rep(i,0,5)cin>>a[i]; ll ok=0,ng=INF; while(ng-ok>=2){ ll mid=(ok+ng)/2; Dinicdinic(12); rep(i,0,5){ ll from=i; vectorto(2); to[0]=(i+4)%5+5; to[1]=(i+1)%5+5; rep(j,0,2)dinic.add_edge(from,to[j],INF); dinic.add_edge(10,i,-min(0LL,a[i]-mid)); dinic.add_edge(i+5,11,-min(0LL,a[i]-mid)); } ll mx=dinic.max_flow(10,11); ll sum=0; rep(i,0,5)sum-=min(0LL,a[i]-mid); if(sum-mx+(mx+1)/2<=mid)ok=mid; else ng=mid; } cout<