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