#include #include #include #include #include using namespace std; int main() { size_t n; char step; cin >> n; int level = 0; int num = 0; bool isInValley = false; for (size_t i = 0; i < n; ++i) { cin >> step; if (step == 'U') { ++level; if (level == 0) { ++num; isInValley = false; } } else if (step == 'D') { if (level == 0) { isInValley = true; } --level; } } cout << num; return 0; }