#include #include #include #include #include using namespace std; int main() { int n; cin >> n; cin.ignore(numeric_limits::max(), '\n'); string steps = ""; getline(cin, steps); int numVals = 0; int valley = 0; int currentLvl = 0; for (char& c : steps){ if (c == 'U'){ currentLvl++; }else{ currentLvl--; } if (currentLvl == 0 && valley == 1){ //Just exited valley numVals++; valley = 0; }else if (currentLvl < 0 && valley == 0){ // Just entered valley valley = 1; } } cout << numVals; return 0; }