// // 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 += min(d,e); return downMiddle; } else { downMiddle += b; a -= b; } int down = min(a,c); if(e <= d) { downMiddle += e; return downMiddle; } else { downMiddle += d; e -= d; downMiddle += 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) { int x = std::min(std::min(d,c)+a,b) + std::min(std::min(a,c)+d,e); if(x > tmp) tmp = x; } //cout << tmp << endl; if(tmp < min) min = tmp; /*int tmp = std::min(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; }