#include #include #include #include #include using namespace std; int main() { int n; std::cin >> n; int altitude = 0; int valleys = 0; for(int i = 0; i < n; i++) { char c; std::cin >> c; int altitudeAtLastStep = altitude; if(c == 'U') { altitude++; } else if(c == 'D') { altitude--; } // took a step from sealeavel into the valley if(altitudeAtLastStep == 0 && altitude == -1) { valleys++; } } std::cout << valleys << '\n'; return 0; }