#include using namespace std; long long algo(){ long long a, b, c, d, e, x, y; cin >> a >> b >> c >> d >> e; x = min(a,b), y=min(d,e); return x + y + max(min(min(d-y, c), b-x), min(min(a-x,c), e-y)); } int main(){ std::ios_base::sync_with_stdio(false); long long saved_sheep, ninput; cin >> ninput; saved_sheep = algo(); //cout << saved_sheep; while (--ninput){ saved_sheep = min(saved_sheep, algo()); } cout << saved_sheep << endl; }