#include #include #include #include #include using namespace std; int main() { int n; cin >> n; int nvalleys = 0; int height = 0; char step; for (int i = 0; i < n; i++) { cin >> step; if (step == 'U') { height++; if (height == 0) { nvalleys++; } } else if (step == 'D') { height--; } else { cerr << "Invalid step " << step << endl; exit(1); } } cout << nvalleys; return 0; }