#include #include #include #include #include #include using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n = 0; string steps; cin >> n; cin >> steps; int valleys = 0; int height = 0; //sea level bool inValley = false; int i=0; for (auto c : steps) { if (c == 'D') --height; else ++height; if (height == -1 && !inValley) { inValley = true; ++valleys; } else if (height == 0) inValley = false; if (++i == n) break; } cout << valleys << endl; return 0; }