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