#include #include #include #include #include using namespace std; int gettotalvalleys(vector hike, int step) { int down = 0; int up = 0; int valley_ctr = 0; bool valley_chk = false; for(int j = 0; j < step; j++) { if(hike[j] == 'D') down++; else up++; if(down > up && valley_chk == false){ valley_ctr++; valley_chk = true; } else if(up >= down) { valley_chk = false; } else { continue; } } return valley_ctr; } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int steps, valleys; cin >> steps; vector hike(steps); for(int i = 0; i < steps; i++){ cin >> hike[i]; } valleys = gettotalvalleys(hike, steps); cout << valleys; }