#include #include #include size_t solve(size_t A, size_t B, size_t C, size_t D, size_t E) { size_t ab = std::min(A, B); size_t de = std::min(D, E); size_t a_ab = A - ab; size_t d_de = D - de; size_t b_ab = B - ab; size_t e_de = E - de; size_t result1 = ab + de; size_t result2 = std::min(C, a_ab == 0 ? std::min(d_de, b_ab) : std::min(a_ab, e_de)); return result1 + result2; } int main() { int n; size_t A, B, C, D, E; scanf("%d", &n); size_t result = -1; for (int i = 0; i < n; ++i) { scanf("%ld %ld %ld %ld %ld", &A, &B, &C, &D, &E); size_t m = solve(A, B, C, D, E); result = result < m ? result : m; } printf("%ld\n", result); return 0; }