#include using namespace std; size_t maxElement(size_t a, size_t b, size_t c, size_t d, size_t e) { size_t result = 0; if (b > a) { result += a; b -= a; a = 0; } else { result += b; a -= b; b = 0; } if (e > d) { result += d; e -= d; } else { result += e; d -= e; e = 0; } if (b == 0 && e == 0) return result; if (b != 0) { if (d != 0) { result += min(min(d, c), b); return result; } } if (e != 0) { if (a != 0) { result += min(min(a, c), e); return result; } } return result; } int main() { int n; cin >> n; size_t result = UINT64_MAX; for (int i = 0; i < n; ++i) { size_t a, b, c, d, e; cin >> a >> b >> c >> d >> e; size_t current = maxElement(a, b, c, d, e); if (result > current) result = current; } cout << result; return 0; }