#include #include #include #include using namespace std; struct Segment { long long A, B, C, D, E; Segment(long long a, long long b, long long c, long long d, long long e) { A = a; B = b; C = c; D = d; E = e; } long long capacity() { long long s = 0; long long AB = min(A, B); s += AB; A -= AB; B -= AB; long long DE = min(D, E); s += DE; D -= DE; E -= DE; long long ACE = max(min(min(A, C), E), min(min(D, C), B)); s += ACE; return s; } }; int main() { long long N; cin >> N; vector segments; for (long long i = 0; i < N; i++) { long long a, b, c, d, e; cin >> a >> b >> c >> d >> e; segments.push_back(Segment(a, b, c, d, e)); } vector capacities; for (long long i = 0; i < N; i++) { capacities.push_back(segments[i].capacity()); } long long minimum = pow(10, 9) + 1; for (long long i = 0; i < capacities.size(); i++) { if (capacities[i] < minimum) minimum = capacities[i]; } cout << minimum << endl; return 0; }