#include using namespace std; #define For(i, a, n) for(int i =a;i pii; template void dbg(Args&&... args){ ((cerr< pair operator+(const pair&a, const pair& b){ return {a.first +b.first, a.second + b.second}; } template ostream& operator<< (ostream& os, const pair& a){ return os<<"("< basic_ostream& operator<<(basic_ostream& os, const C&c){ for(auto it=begin(c); it!=end(c);++it){ os<<(it==begin(c)?"":" ")<<*it; } return os; } void solve(){ int n;cin>>n; ll x = 12312432141234; For(i, 0, n){ ll a, b, c, d, e;cin>>a>>b>>c>>d>>e; ll t = min(a, b) + min(d, e); ll s = max(min(a-b, min(c, e-d)), min(d-e, min(c, b-a))); t+= max(s, (ll)0); x = min(x, t); } cout<sync_with_stdio(0); cin.exceptions(cin.failbit); int t=1;//cin>>t; while(t--){ solve(); } }