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 */ string n = Console.ReadLine(); char[] arr = Console.ReadLine().ToCharArray(); Console.WriteLine(CountValleys(arr)); } static int CountValleys(char[] arr){ int valleys = 0; int position = 0; bool inValley = false; foreach(char item in arr){ position = item == 'U' ? position += 1 : position -= 1; if (position == -1 && !inValley){ inValley = true; valleys += 1; } else if (position == 0 && inValley){ inValley = false; } } return valleys; } }