#include #include #include #include #include using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n; cin >> n; string hike; cin >> hike; int fromSeaLevel = 0; int valleyCount = 0; bool inValley = false; for (int i = 0; i < n; i++) { if (hike[i] == 'U') { fromSeaLevel++; } else { fromSeaLevel--; } if (fromSeaLevel < 0) { inValley = true; } if (inValley && fromSeaLevel == 0) { valleyCount++; inValley = false; } } cout << valleyCount << endl; return 0; }