#include int main() { unsigned int N; int a = scanf("%u", &N); int min_flow = 9999999; int flow =0; for(int i = 0; i < N; i++) { int A, B, C, D, E; a = scanf("%d %d %d %d %d", &A, &B, &C, &D, &E); int res =0; if(A > B) { flow += B; res = A-B; if (C> res){ D+=res; }else{ D+=C; } if (D > E){ flow +=E; } else { flow += D; } }else { flow += A; res = B -A; } if(D > E && A < B) { flow += E; int res1 = D -E; if(C > res1) { if (res > res1){ flow += res1; }else { flow += res; } }else{ if (C < res){ flow+=C; } else{ flow +=res; } } } if(flow < min_flow) min_flow = flow; } printf("%d\n", min_flow); }