#include #include #include #include using namespace std; int main(){ int N, min_sheep = INT32_MAX; cin >> N; for (int i = 0; i < N; i++){ int a,b,c,d,e; cin >> a >> b >> c >> d >> e; //cout << a << " " << b << " " << c << " " << d << " " << e << endl; //int sheep = max(min(d+c, e) + min(a-c, b), min(a+c, b) + min(d-c, e)); int sheep = min(b, a + min(d,c)) + min(e, d + min(a,c)); min_sheep = min(sheep, min_sheep); /* int sheep = 0; if (a >= b){ sheep += b; b = 0; } else { sheep += a; b = b - a; } if (c >= d){ sheep += d; d = 0; } else { sheep += c; d = d - c; } */ //cout << sheep << endl; } cout << min_sheep << endl; return 0; }