#include #include #include using namespace std; int main(int argc, char const *argv[]) { ios::sync_with_stdio(0); int n; vector steps; char step; int valley; int prev, cur; cin >> n; for (int i = 0; i < n; ++i) { cin >> step; steps.push_back(step); } valley = 0; prev = cur = 0; for (int i = 0; i < n; ++i) { if (steps[i] == 'U') { cur++; } else { //if (steps[i] == 'D') cur--; } if (prev == 0) { if (cur < 0) { valley++; } } prev = cur; } cout << valley << '\n'; return 0; }