#include using namespace std; int main() { int N; cin >> N; int minimal_capacity = INT32_MAX; for (int i = 0; i < N; ++i) { int A, B, C, D, E; cin >> A >> B >> C >> D >> E; int value = -1; if(A <= B && D <= E) { value = A + D; } else if(A < B && D > E) { int help = min((D - E), C); int help1 = min(A + help, B); value = E + help1; }else if (A > B && D < E){ int help = min(A - B, C); int help1 = min(D + help, E); value = (B + help1); }else if(A > B && D > E){ value = B + E; }else if (A == B){ value = A + min(D, E); }else if (D == E){ value = D + min(A, B); } minimal_capacity = min(minimal_capacity, value); } cout << minimal_capacity << endl; return 0; }