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 n = Convert.ToInt32(Console.ReadLine()); char[] steps = Console.ReadLine().ToCharArray(); int balance = 0; int prevBalance = 0; int valleyCount = 0; for (int i = 0; i < n; i++) { prevBalance = balance; if (steps[i] == 'U') { balance++; } else if (steps[i] == 'D') { balance--; } if (i > 0 && balance == 0) { if (prevBalance < 0) { valleyCount++; } } } Console.WriteLine(valleyCount.ToString()); } }