#include using namespace std; typedef long long int ll; typedef double ld; typedef pair ii; typedef vector vi; typedef vector vii; #define PB push_back #define ff first #define ss second #define MP make_pair #define FOR(p,a,b) for( ll p = (a); p < (ll)(b); ++p) #define F(a) FOR(i,0,a) #define FF(a) FOR(j,0,a) #define EPS (1e-10) #define EQ(a,b) (fabs(a-b) <= fabs(a+b)*EPS) ll findmin(ll a, ll b, ll c, ll d, ll e) { ll res = 0; ll min1 = min(a,b); ll min2 = min(d,e); res += min1 + min2; a -= min1; b -= min1; d -= min2; e -= min2; if(b==e && b==0) return res; if(a==d && a==0) return res; if(c==0) return res; if(a==0) return res + min(min(d,c),b); if(d==0) return res + min(min(c,a),e); return res; } int main() { ll n, a, b, c, d, e, globmin = 100000000, tmp; scanf(" %lld",&n); F(n) { scanf(" %lld %lld %lld %lld %lld",&a, &b, &c, &d, &e); tmp = findmin(a,b,c,d,e); if(tmp < globmin) globmin = tmp; } printf("%lld\n",globmin); return 0; }