#include #include using namespace std; int main(){ int n; int current_level = 0; int valleys = 0; int mountains = 0; string steps; cin >> n >> steps; for(int i = 0; i < n; ++i){ if (steps[i] == 'U'){ ++current_level; if (current_level == 0){ //If we stepped up and are now at 0, that was the end of a valley ++valleys; } } else if (steps[i] == 'D'){ --current_level; if (current_level == 0){ //If we stepped down and are now at 0, that was the end of a mountain ++mountains; } } } cout << valleys; return 0; }