#include using namespace std; using ll = long long; using pii = pair; template using V = vector; template using VV = V>; #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) #define per(i, b) per2(i, 0, b) #define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define ALL(c) (c).begin(), (c).end() constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template void chmin(T& t, const U& u) { if (t > u) t = u; } template void chmax(T& t, const U& u) { if (t < u) t = u; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } template ostream& operator<<(ostream& os, const vector& v) { os << "{"; rep(i, v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } #ifdef LOCAL void debug_out() { cerr << endl; } template void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif #define FOR(i, c) for (typeof(c.begin()) i = c.begin(); i != c.end(); ++i) #define REP(i, n) for (int i = 0; i < n; ++i) #define fst first #define snd second #define double long double const double EPS = 1e-6, INF = 1. / 0.; double simplexMethodPD(double c[], int n, double b[], int m, double A[]) { double T[m + 1][n + m + 1]; memset(T, 0, sizeof(T)); REP(j, m) { REP(i, n) T[j][i] = A[j * n + i]; T[j][n + j] = 1; T[j][n + m] = b[j]; } REP(i, n) T[m][i] = c[i]; while (1) { int p = 0, q = 0; REP(i, n + m) if (T[m][i] <= T[m][p]) p = i; REP(j, m) if (T[j][n + m] <= T[q][n + m]) q = j; double t = min(T[m][p], T[q][n + m]); if (t >= -EPS) return -T[m][n + m]; // optimal if (t < T[q][n + m]) { // tight on c -> primal update REP(j, m) if (T[j][p] >= EPS) if (T[j][p] * (T[q][n + m] - t) >= T[q][p] * (T[j][n + m] - t)) q = j; if (T[q][p] <= EPS) return INF; // primal infeasible } else { // tight on b -> dual update REP(i, n + m + 1) T[q][i] *= -1; REP(i, n + m) if (T[q][i] >= EPS) if (T[q][i] * (T[m][p] - t) >= T[q][p] * (T[m][i] - t)) p = i; if (T[q][p] <= EPS) return -INF; // dual infeasible } REP(i, m + n + 1) if (i != p) T[q][i] /= T[q][p]; T[q][p] = 1; // pivot(q,p) REP(j, m + 1) if (j != q) { double alpha = T[j][p]; REP(i, n + m + 1) T[j][i] -= T[q][i] * alpha; } } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll a, b, c, d, e; cin >> a >> b >> c >> d >> e; double A[25]; rep(i, 5) rep(j, 5) { A[i * 5 + j] = 0.0; int w = i - j; if (w < 0) w += 5; if (w <= 2) A[i * 5 + j] = 1.0; } double B[5] = {a, b, c, d, e}; double C[5] = {-1, -1, -1, -1, -1}; auto res = simplexMethodPD(C, 5, B, 5, A); cout << ll(-res) << endl; return 0; }