#include #include #include #include #include using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int numSteps{}; int prevLoc{}; int curLoc{}; int numValley{}; char direction{}; cin >> numSteps; for (int i = 0; i < numSteps; ++i) { cin >> direction; if (direction == 'U') { prevLoc = curLoc; curLoc++; } else if (direction == 'D') { prevLoc = curLoc; curLoc--; } if (prevLoc == 0) { if (curLoc < 0) { numValley++; } } } cout << numValley; return 0; }