#include using namespace std; #define ll long long void solve() { int r; cin >> r; vector> va (r); for(int i = 0; i < r; i++){ for(int x = 0; x < 5; x++){ ll a; cin >> a; va[i][x] = a; } } vector max; ll minVal = LLONG_MAX; for(int i = 0; i < r; i++){ ll x = va[i][1] -va[i][0]; ll y = va[i][4] -va[i][3]; if((x >= 0 && y >= 0) || (x <=0 && y <=0 )){ minVal = min(minVal, min(va[i][1], va[i][0]) + min(va[i][3], va[i][4])) ; } if(x < 0 && y > 0){ minVal = min(minVal, min(va[i][1], va[i][0]) + min(va[i][3] + min((ll)abs(x), va[i][2]), va[i][4])); } else{ auto val = min(va[i][3], va[i][4]) + min(va[i][0] + min((ll)abs(y), va[i][2]), va[i][1]); minVal = min(val, minVal); } } cout << minVal << endl; } int main(){ solve(); }