// // Created by cteam37 on 10/19/24. // #include using namespace std; int DownMiddle (int a, int b, int c, int d, int e) { int downMiddle = 0; if(b >= a) { downMiddle += a; downMiddle += std::min(d,e); return downMiddle; } else { downMiddle += b; a -= b; } int down = std::min(a,c); if(e <= d) { downMiddle += e; return downMiddle; } else { downMiddle += d; e -= d; downMiddle += std::min(down, e); } return downMiddle; } int main() { int numOfInput; cin >> numOfInput; int32_t min = INT32_MAX; for (int i = 0; i < numOfInput; ++i) { int a,b,c,d,e; cin >> a; cin >> b; cin >> c; cin >> d; cin >> e; /*int tmp = 0; for (int j = -c; j <= c; ++j) { if (c > d) continue; int x = std::min(a-c,e) + std::min(d+c,e); if(x > tmp) tmp = x; } //cout << tmp << endl; if(tmp < min) min = tmp;*/ int tmp = std::max(DownMiddle(a,b,c,d,e), DownMiddle(d,e, c,a,b)); //cout << tmp << endl; if (tmp < min) min = tmp; } cout << min << endl; return 0; }