#include #include #include #include #include using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n; string s; cin >> n; cin >> s; const char *x = s.c_str(); int counter = 0, v = 0; bool down = false; for (int i = 0; i < n; i++) { if (counter < 0) { down = true; } else { down = false; } if (s[i] == 'U') { counter++; } if (s[i] == 'D') { counter--; } if (counter == 0 && down) { v++; } } cout << v << endl; return 0; }