#include #include #include using namespace std; typedef long long ll; const ll INF = (1LL << 62) - 1; bool solve(vector v, ll target) { for (auto &x:v)x -= target; int maxPos = 0; for (int i = 0; i < 5; i++) { if (v[maxPos] < v[i]) maxPos = i; } ll addCount = 0; if (v[maxPos] <= -2) { addCount += (-v[maxPos]) / 2 * 5; for (auto &x:v)x += addCount / 5 * 2; } ll left = 0; vector tmp = v; for (int i = 0; i < 5; i++) { int here = (maxPos + i) % 5; if (tmp[here] < 0) { ll add = -tmp[here]; left += add, tmp[here] += add, tmp[(here + 1) % 5] += add; } } ll right = 0; tmp = v; for (int i = 0; i < 5; i++) { int here = (maxPos - i + 5) % 5; if (tmp[here] < 0) { ll add = -tmp[here]; right += add, tmp[here] += add, tmp[(here - 1 + 5) % 5] += add; } } addCount += min(left, right); return addCount <= target; } int main() { vector v(5); for (int i = 0; i < 5; i++)cin >> v[i]; ll ok = 0, ng = 1e16; while (ng - ok > 1) { ll mid = ok + (ng - ok) / 2; if (solve(v, mid))ok = mid; else ng = mid; } cout << ok << endl; return 0; }