#include #include using namespace std; int main(){ int numberOfSegments; cin >> numberOfSegments; int total = 0; for(int i = 0; i> input; intarr[j] = stoi(input); } int topgate = intarr[1]; int toppass = 0; if(intarr[0] < intarr[1]) { toppass += intarr[0]; topgate -= toppass; } else { toppass += intarr[1]; topgate = 0; } int bottomgate = intarr[3]; int bottompass = 0; if(intarr[3] < intarr[4]) { bottompass += intarr[3]; bottomgate -= bottompass; }else { bottompass += intarr[4]; bottomgate = 0; } //if(bottomgate != 0 || topgate != 0) { int topleft = intarr[0] - toppass; int bottomleft = intarr[3] - bottompass; //cout << "top " << topleft << endl; //cout << "bottom " << bottomleft << endl; if(topleft >= bottomleft) { if(intarr[2] >= topleft) { bottompass += topleft; intarr[2] -= topleft; } else { bottompass += intarr[2]; intarr[2] = 0; } } else//(topleft < bottomleft) { if(intarr[2] >= bottomleft) { toppass += bottomleft; intarr[2] -= bottomleft; } else { toppass += intarr[2]; intarr[2] = 0; } } //intarr[3] - intarr[2]; } //cout << "top pass " << toppass << " bottom pass " << bottompass << endl; //cout << toppass + bottompass << endl; if(total != 0) { if(toppass + bottompass <= total) { total = toppass + bottompass;} }else { total = toppass + bottompass; } } cout << total//<< endl; return 0; }