using System; using System.Linq; class Solution { static void Main() { Console.ReadLine(); // N is not needed var steps = Console.ReadLine().ToCharArray().Select(c => c == 'U'); var valleysCount = 0; bool inValley = false; var height = 0; foreach (var stepUp in steps) { if (stepUp) { if (inValley && (height == -1)) { inValley = false; ++valleysCount; } } else { // step down if (height == 0) { // entering valley inValley = true; } } height += stepUp ? 1 : -1; } Console.WriteLine(valleysCount); } }