#include #include #include #include #include using namespace std; int main() { int n; cin >> n; int height = 0; bool inValley = false; int valleys = 0; for (int i = 0; i < n; i++) { char val; cin >> val; if (val == 'U') { height++; if (height == 0 && inValley) { //lastPeak = height; valleys++; inValley = false; } } else // val == D { if (height == 0) { //lastPeak = height; inValley = true; } height--; } } if (inValley) valleys++; cout << valleys << endl; return 0; }