# Enter your code here. Read input from STDIN. Print output to STDOUT steps = gets.chomp.to_i hike = gets.chomp array = hike.split("") level = 0 hill = 0 hills = 0 valley = 0 valleys = 0 steps.times do |n| if array[n] == "U" level += 1 if level > 1 hill += 1 elsif level == 0 && valley > 0 valleys += 1 end elsif array[n] == "D" level -= 1 if level < 1 valley += 1 elsif level == 0 && hill > 0 hills += 1 end end end # puts "Hills: #{hills}, valleys#{valleys}" puts hills + valleys