#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; int sheep = 0; if (a >= b){ sheep += b; a = a - b; b = 0; } else { sheep += a; b = b - a; a = 0; } if (d >= e){ sheep += e; d = d - e; e = 0; } else { sheep += d; e = e - d; d = 0; } if (b == 0 && e == 0){ min_sheep = min(sheep, min_sheep); continue; } else if (b == 0){ if (a > 0 && c > 0 && e > 0){ sheep += min({a, c, e}); } } else if (e == 0){ if (d > 0 && c > 0 && b > 0){ sheep += min({d, c, b}); } } //cout << a << " " << b << " " << c << " " << d << " " << e << endl; //cout << sheep << endl; min_sheep = min(sheep, min_sheep); } cout << min_sheep << endl; return 0; }