#include #include #include #include #include using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int stepCount = 0; string steps; cin >> stepCount >> steps; int valley = 0; int totalClimb = 0; bool isValley = false; for(int i = 0; i < steps.length(); i++ ) { if(steps[i] == 'U') { totalClimb++; } if(steps[i] == 'D') { if(totalClimb == 0 && isValley == 0) { isValley = true; } totalClimb--; } if(totalClimb == 0 && isValley) { valley++; isValley = false; } } cout << valley; return 0; }