#include #include #include #include #include using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int steps = 0; cin >> steps; string in = ""; cin >> in; int height = 0; int valleys = 0; for(int i = 0; i < steps; i++){ if(in.at(i) == 'U' && height == 0){ //found mountain while (i < steps){ if(in.at(i) == 'U') height ++; else height --; if(height == 0) break; i++; } }else if(in.at(i) == 'D' && height == 0){ //found valley valleys ++; while(i < steps){ if(in.at(i) == 'U') height ++; else height --; if(height == 0) break; i++; } } } cout << valleys; return 0; }