using System; using System.Collections.Generic; using System.IO; class Solution { static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); char[] temp = Console.ReadLine().ToCharArray(); //int[] input = Array.ConvertAll(temp, int.Parse); int height = 0; bool inValley = false; bool outSideValley = true; int valleys = 0; for (int i = 0; i < n; i++) { if (temp[i]=='U') { height++; } else { height--; } if (outSideValley) { if (height == -1) { inValley = true; valleys++; outSideValley = false; } } if (height==0) { outSideValley = true; } } Console.WriteLine(valleys); /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */ } }