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