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 = int.Parse(Console.ReadLine()); string steps = Console.ReadLine(); int sealevel = 0; Boolean valleyflag = false; int countValleys = 0; for(int x=0; x<=(n-1); ++x){ if(steps[x]=='D'){ sealevel = sealevel - 1; }else{ sealevel = sealevel + 1; } if (sealevel <= -1){ //He is entering a valley set flag. valleyflag = true; } if (sealevel == 0 && valleyflag==true){ //exiting valey set flag valleyflag = false; countValleys = countValleys + 1; } } Console.WriteLine(countValleys.ToString()); } }