#include #include #include #include #include using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int numSteps; string path; cin >> numSteps; cin >> path; int altitude = 0; int valleys = 0; bool isValley = false; for(int i =0; i < numSteps;){ isValley = false; if(path[i] == 'D'){ while(path[i] == 'D' && i < numSteps){ i++; altitude--; // cout << "D"; } for(;altitude < 0 && i < numSteps;i++){ isValley = true; if(path[i] =='D'){ altitude--; //cout << "d"; } else{ altitude++; //cout << "u"; } } if(isValley) valleys++; } else { //cout << "U"; altitude++; i++; } } cout << valleys; return 0; }