using System; using System.Collections.Generic; using System.IO; class Solution { static void Main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */ int numberofSteps = Convert.ToInt32(Console.ReadLine()); string stepLog = Console.ReadLine(); int numberOfValleys = 0; int elevation = 0; bool atSeaLevel = true; for (int stepIndex = 0; stepIndex < numberofSteps; stepIndex++) { if (atSeaLevel && stepLog[stepIndex] == 'D') { numberOfValleys++; } if (stepLog[stepIndex] == 'D') { elevation--; } else { elevation++; } if (elevation == 0) { atSeaLevel = true; } else { atSeaLevel = false; } } Console.WriteLine(numberOfValleys); } }