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