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 len = Int32.Parse(Console.ReadLine()); string steps = Console.ReadLine(); int position = 0; bool movingup = false, belowSeaLevel = false; int valleys = 0; for(int i = 0; i < len; i++){ if(steps[i] == 'U'){ movingup = true; position += 1; }else{ movingup = false; position -= 1; } belowSeaLevel = position < 0 ? true : false; if(position == 0 && movingup == true && belowSeaLevel == false) valleys++; } Console.WriteLine(valleys); } }